为什么在Material UI Dialog组件的三元运算符中使用回调作为条件



我正试图根据本节文档重新创建Material UI Customized Dialog组件,我不明白为什么回调函数onClose条件用于在DialogTitle:中显示IconButton组件

<DialogTitle sx={{ m: 0, p: 2 }} {...other}>
{children}
{onClose ? (
<IconButton
aria-label="close"
onClick={onClose}
sx={{
position: 'absolute',
right: 8,
top: 8,
color: (theme) => theme.palette.grey[500],
}}
>
<CloseIcon />
</IconButton>
) : null}
</DialogTitle>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

据我所知,如果您正确设置了状态,IconButton总是被渲染的。我只是想知道在三元运算符中使用onClick回调函数是否有特定的原因或模式?我试图完全去掉三元运算符,一切都一样。

如果没有onClose函数,按钮将失去所有用途,我的意思是它的全部目的是运行回调。因此,如果没有回调,那么就不要显示按钮。

最新更新