Home > Back-end >  How to use if condiiton in Reactjs
How to use if condiiton in Reactjs

Time:12-12

I am working with Reactjs and using nextjs framework,I am getting User data including "category name (cat_name)" which he selected,Now i want to display that category in drop down,How can i do this ? My category showing with {post?.cat_name},Now i want to add condition (select=selected) in nextjs, Here is my current code

 <select className="form-control" name="cat_name" id="cat_name" >
    <option value="">Select Category</option>
    <option value="pined" {//want select condition here} >Pined</option>
 </select>

CodePudding user response:

Add value attribute to select and it will pre-select the option based on the option value

<select value={post?.cat_name} className="form-control" name="cat_name" id="cat_name" >
    <option value="">Select Category</option>
    <option value="pined"   >Pined</option>
 </select>
  • Related