[英]Close modal A after opening modal B from modal A in reactjs with react-bootstrap
The case is like I have a registration button and when I am clicking on that then signup modal will popup.这种情况就像我有一个注册按钮,当我点击它时,会弹出注册模式。 Now I want to open Login modal from signup modal but signup modal should be closed after login modal popped up.
现在我想从注册模式打开登录模式,但是在登录模式弹出后应该关闭注册模式。
show={this.props.signupModalOn}
onHide={this.props.onSignupModalCall}
show={this.props.loginModalOn}
onHide={this.props.onLoginModalCall}
Here is the code for ModalA.js and ModalB.js这是 ModalA.js 和 ModalB.js的代码
I tried some cases and I am getting nested popup modal but the first modal is not getting closed.我尝试了一些情况,我得到了嵌套的弹出模式,但第一个模式没有关闭。
As the Sign-Up modal is handled by the parent of the component you have to pass down the setState
function to be able to update it in the child component.由于注册模式由组件的父级处理,因此您必须传递
setState
function 才能在子组件中更新它。 Let's call the function parentStateUpdate
and the state value signUpModalOn
for simplicity:为简单起见,我们将 function
parentStateUpdate
和 state 值signUpModalOn
:
<ModalA parentStateUpdate={value => this.setState({ signUpModalOn: value })} />;
Then you can modify onLoginModalCall
like this:然后你可以像这样修改
onLoginModalCall
:
onLoginModalCall = () => {
this.setState({ loginModalOn: !this.state.loginModalOn, static: true });
parentStateUpdate({ signUpModalOn: false });
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.