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

Show/hide group of elements with conditional rendering

The code below does hides/shows if in the conditional rendering is only one element either label or text input but it doesn’t work if I want to hide both elements. I need solution which will hide at least 2 or more elements.

 {trueMode === false && (<label htmlFor="car">Car</label> && 
                         <input onChange={handleChange} id="car" 
                                value={newVehicle.car} type="text" />)}
    

>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

You have to wrap the elements with a fragment for example

{trueMode === false && (
  <>
    <label htmlFor="car">Car</label>
    <input onChange={handleChange} id="car" value={newVehicle.car} type="text" />
  </>
)}
    
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