use*_*468 4 jsx reactjs react-native
如何在jsx:ReactJS中使用if条件?我只想如果
if user == "author" or "supervisor":
<IconButton
aria-label="delete"
onClick={() => props.pressHandler(props.id)}
>
<DeleteIcon style={{ color: 'red' }} />
</IconButton>
else
no delete button
Run Code Online (Sandbox Code Playgroud)
只要把它们戴上大括号,
{ ["author", "supervisor"].includes(user) &&
<IconButton
aria-label="delete"
onClick={() => props.pressHandler(props.id)}
>
<DeleteIcon style={{ color: 'red' }} />
</IconButton> || null }
Run Code Online (Sandbox Code Playgroud)
参考:https://reactjs.org/docs/conditional-rendering.html#inline-if-with-logic--operator
| 归档时间: |
|
| 查看次数: |
143 次 |
| 最近记录: |