【发布时间】:2021-07-21 14:29:08
【问题描述】:
我对 reactJS 还很陌生,我正在尝试像这样使用引导模式:
class Footer extends Component {
render() {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
return (
<footer className="footer-bottom">
<Container>
<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>Woohoo, you're reading this text in a modal!</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary" onClick={handleClose}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
</Container>
</footer>
);
}
}
但是我收到了这个错误:
Invalid hook call. Hooks can only be called inside of the body of a function component.
我的问题是如何将我的 const (show、setShow、handelClose、handelShow) 变成一个函数来让它工作?
【问题讨论】: