[英]How to display Modal component on page load?
I'm making an HTML5 game page and wanted to have my login form be a modal when the user loads the page. 我正在制作一个HTML5游戏页面,并希望在用户加载页面时使我的登录表单成为模式页面。 I have set the state to true and tried moving the state to app.js but neither works 我已将状态设置为true,并尝试将状态移动到app.js,但均无效
export default class Modal extends Component {
state = { show: true };
showModal = () => {
this.setState({ show: true });
};
hideModal = () => {
this.setState({ show: false });
};
render() {
return (
<div className="modal">
<section className="modal-main">
<Login username={this.props.username} email={this.props.email} password={this.props.password} />
<button onClick={this.hideModal}>close</button>
</section>
</div>
);
}
}
I have the modal imported into app.js but it still is not loading. 我已将模式导入到app.js中,但仍未加载。
You can use something like: 您可以使用类似:
render() {
return (
<div className="modal">
<section className="modal-main">
{this.state.show &&
<Login username={this.props.username} email={this.props.email} password={this.props.password} />
}
<button onClick={this.hideModal}>close</button>
</section>
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.