React show these div if true

Viewed 21369

I'm still new to React and having a hard time trying to figure out how to show div element content if props return true. I know I can only return one render in a function but how can I achieve this. Can I write some type Jsx inline if statement?

<div>if true show</div> 
<div>if true show</div> 
<div>false don't show</div> 
<div>if true show</div> 

Update: I actually used

{this.props.test === true &&
    <div>if true show</div>
  }
4 Answers

here new exaple for new developer

const [ role, setRole ] = useState('');

const onClick = () => setRole('admin');

<input type='button' onClick={onClick} value='i am admin' />

   {role == 'admin' &&
    <div className='admin'>{'this section view using react... '}
      </div>    
  }
Related