javascript - 刷新页面时响应自定义模态显示模态内容毫秒
问题描述
我建立了一个反应自定义模式。通过单击打开按钮 showModal 变为真,使显示块和关闭按钮使显示不显示。
但是我在刷新页面时注意到了一个错误,模式的内容在屏幕上显示了几毫秒。
这是我的应用程序的重要功能之一。
这是视频链接https://youtu.be/A6CUmSzwobY
和
codepen link https://codepen.io/alligatorio/pen/aYzMKL?editors=0100
如果有人能指出问题以及如何解决,我将不胜感激。
解决方案
return null
如果模态关闭,您可以。这样,模态只有在应该打开的情况下才会添加到 DomTree。
const Modal = ({ handleClose, show, children }) => {
// If the modal is closed, return null
if (!show) {
return null;
}
// Modal is open, render it
return (
<div className={'modal display-block'}>
<section className='modal-main'>
{children}
<button
onClick={handleClose}
>
Close
</button>
</section>
</div>
);
};
推荐阅读
- c# - C# - 如何使以下类成为基类,以便子类可以具有相同的属性、方法?
- css - Chrome 检查器显示黄色边框区域,但没有边框值
- reactjs - React 在混合对象和回调方法时如何批量设置状态?
- javascript - 如何迭代数组值字典以呈现组件?反应JS
- sql - SQL 查询以显示另一个表中的缺失记录
- java - Kotlin:ObjectBox 和 kotlinx.Serialization 的组合实体类冲突?
- java - 如何解析存储在 Zookeeper /hbase/region-in-transition 子节点中的数据?
- c++ - 我的反向传播正在产生完全的垃圾
- python - Python / pandas合并两个数据框
- java - Spring 不会为方法参数验证调用 Hibernate 验证器