mat*_*lev 5 javascript reactjs material-ui
当使用 Material-UI 的 Modal 组件(或使用它构建的任何组件)时,使用open
prop 与有条件渲染组件相比有什么好处吗?我注意到你失去了很好的结束过渡,但是如果有很多模态框,会有任何性能优势吗?
使用道具的示例open
:
const [openModal, setOpenModal] = React.useState(false);
return (
/* code to set openModal to true */
<Modal open={openModal} onClose={() => setOpenModal(false)}>modal stuff here...</Modal>
);
Run Code Online (Sandbox Code Playgroud)
使用条件渲染的示例:
const [openModal, setOpenModal] = React.useState(false);
return (
/* code to set openModal to true */
{
openModal &&
<Modal open onClose={() => setOpenModal(false)}>modal stuff here...</Modal>
}
);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
637 次 |
最近记录: |