Home > Blockchain >  ReactJS - Multiple modals
ReactJS - Multiple modals

Time:10-28

I am trying to create a simple modal form using react. I have achieved something like this [https://codesandbox.io/s/simple-modal-box-with-react-forked-0nlcr][1].

When I click on the 'save' button from the modal, it should save and show a thank you/confirmation message in another modal.

How to deal with multiple modals in such a scenario? Is it something I can achieve it modifying the Modal.js? Can someone guide me on how to implement that in the shared example?

Thanks

CodePudding user response:

Actually, you have only one modal on your code. For showing another Modal by clicking the "Save" button, you can just implement the same way you are showing the "Hello Modal" modal when clicking "Open Modal".

You will need two separate states to handle two separate Modal.

CodePudding user response:

You can create as many modals as you need and show/hide setting proper state. E.g.:

...
<Modal show={this.state.shouldShowInputModal} ...>
modal content
</Modal>
<Modal show={this.state.shouldShowConfirmationModal} ...>
confirmation modal content
</Modal>
...
  • Related