Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use if condiiton in Reactjs

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>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading