ReactJS,react-bootstrap,Modal Box:“错误:重新渲染太多。React限制渲染次数以防止无限循环。”
我正在学习ReactJS,并且正在使用react-bootstrap构建我的第一个组件。
我集成的模式没有问题,但我试图检查浏览器是否不是Internet Explorer启动的模式框,并得到这个错误:“modal box:”错误:太多重新渲染。React限制渲染的次数以防止无限循环。“这可能是与正确更新状态相关的一个非常基本的事情,也许你可以帮助我,这是代码:
import React, { useState } from 'react';
import Modal from 'react-bootstrap/Modal';
import Button from 'react-bootstrap/Button';
function ModalStd () {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
const customClass = "modal-std";
function isIE() {
var ua = navigator.userAgent;
var is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;
return is_ie;
}
if (!isIE()) {
handleShow(); // here is the issue I think
}
return (
<>
<Button variant="primary" onClick={handleShow}>
Launch modal
</Button>
<Modal backdropClassName={customClass}
dialogClassName={customClass}
show={show} onHide={handleClose}
animation={false}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body></Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
{/*<Button variant="primary" onClick={handleClose}>
Save Changes
</Button>*/}
</Modal.Footer>
</Modal>
</>
);
}
export default ModalStd;
``
转载请注明出处:http://www.ahddzj.com/article/20230526/2411705.html