我在试图弄清楚如何向我的模态添加一个功能正常的关闭按钮时遇到了很多问题 - 构造函数/道具没有工作,我不确定在按钮元素中的 onClick= 之后放什么。
class Modal extends React.Component {
// whenever component gets rendered to the screen we create a new div assigned to this.modalTarget
componentDidMount() {
this.modalTarget = document.createElement('div');
// add class name to modal target
this.modalTarget.className = 'modal';
// take the div we just created and append it to the body tag in doc
document.body.appendChild(this.modalTarget);
// call method _render
this._render();
}
// whenever the component's about to update we do another render
// this render makes sure …Run Code Online (Sandbox Code Playgroud)