简体   繁体   English

使用 react-bootstrap 从 reactjs 中的模态 A 打开模态 B 后关闭模态 A

[英]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.

相关问题 Reactjs react-bootstrap 模态“容器”属性 - Reactjs react-bootstrap modal “container” property 使用 react-bootstrap 打开模式时出错 - Error when opening a modal with react-bootstrap 如何打开和关闭反应引导模式? - How to open & close react-bootstrap modal? 关闭按钮不适用于 react-bootstrap 模态组件 - Close button isn't working for react-bootstrap modal component React react-bootstrap - 如何从外部组件关闭模态 window - React react-bootstrap - How do I close a modal window from an outside component 如何从 reactjs 中的异步请求中获取数据并将其添加到 React-bootstrap Modal - How to get data from async request in reactjs and add it to React-bootstrap Modal 在 reactjs 中检查 cookie 后显示引导模式(不使用 react-bootstrap 或类似的东西,只使用 cdn 引导) - show bootstrap modal after cookie check in reactjs (not use react-bootstrap or something similar only use cdn bootstrap) 在reactjs中使用react-bootstrap一次显示两个模态时,如何在第一个模态上方和第二个模态下方显示灰色区域? - When showing two modal at a time with react-bootstrap in reactjs, how to show gray area above the first modal and below the second modal? setState 在反应引导模式中不起作用 - setState not work in react-bootstrap modal React-Bootstrap Modal渲染两次 - React-Bootstrap Modal rendering twice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM