Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsx: ReactJS if condition

How to use if condition in jsx: ReactJS? I just want that if the

if user == "author" or "supervisor":
<IconButton 
   aria-label="delete" 
   onClick={() => props.pressHandler(props.id)}
 >
  <DeleteIcon style={{ color: 'red' }} />
</IconButton>
else
     no delete button
like image 823
user14823468 Avatar asked Mar 01 '23 14:03

user14823468


1 Answers

Just put them in braces,

{ ["author", "supervisor"].includes(user) &&
<IconButton 
   aria-label="delete" 
   onClick={() => props.pressHandler(props.id)}
 >
  <DeleteIcon style={{ color: 'red' }} />
</IconButton> || null }

Reference: https://reactjs.org/docs/conditional-rendering.html#inline-if-with-logical--operator

like image 89
Ashish Bairwa Avatar answered Mar 11 '23 12:03

Ashish Bairwa