[英]Conditionally Wrap Button with Another Component
I'm having trouble getting the syntax right to conditionally wrap my OverLay 我无法正确使用语法来有条件地包装我的OverLay
<td>
{uuid === resetEmailValidationUser && popoverTop &&
<OverlayTrigger trigger="click" placement="top" overlay={popoverTop}>
}
<Button
bsSize='xsmall'
className='reset-password-link background-color-dark-grey'
onClick={() => handleResetPassword(uuid, email)}
>
reset password
</Button>
{ uuid === resetEmailValidationUser && </OverlayTrigger>}
</td>
This is not a valid JSX
, it will throw error. 这不是有效的JSX
,它将引发错误。 You can write it like this by using ternary operator
: 您可以使用ternary operator
这样写:
canst button = <Button
bsSize='xsmall'
className='reset-password-link background-color-dark-grey'
onClick={() => handleResetPassword(uuid, email)}
>
reset password
</Button>
<td>
{uuid === resetEmailValidationUser && popoverTop?
<OverlayTrigger trigger="click" placement="top" overlay={popoverTop}>
{button}
</OverlayTrigger>
:
{button}
</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.