我需要一段时间后关闭我的模式,该怎么办?这是我到目前为止所做的
import React from 'react';
import IconcloseModal from './../../assets/icon/icon-cerrar-modal.png';
import './Modal.css'
const Modal = ({ typeModal, textModal, showModal, positionModal, closeModal }) => {
let titleModal = '';
if (typeModal === 'success')
titleModal = '¡Bien hecho!';
else if (typeModal === 'warning')
titleModal = '¡Cuidado!';
return (
<div>
<div className={(showModal) ? 'notify ' + positionModal + ' do-show' : 'notify ' + positionModal}
data-notification-status={typeModal}>
<div className="content-warning">
<h3>{titleModal}</h3>
<p> {textModal}</p>
</div>
<div onClick={closeModal} className="close-alert"><img src={IconcloseModal} alt="Logo cerrar modal" /></div>
</div>
</div>
)
}
export default Modal;
您可以为此使用setTimout函数。假设closeModal
是一个函数,您可以像这样实现它。这将在3秒钟后关闭模态。
function close() {
setTimeout(() => closeModal(), 3000)
}
return(
...
<div onClick={close} className="close-alert"><img src={IconcloseModal} alt="Logo cerrar modal" /></div>
...
)