M
M
maxemga2021-05-21 16:18:58
React
maxemga, 2021-05-21 16:18:58

How to manage multiple modal windows?

Usually, I manage the modal window like this:

const [open, setOpen] = useState(false)

    return(
        {open ?  <Modal></Modal> : null}
    )

But this is with one modal window, and if I want to build a more complex system, as in the picture, for example:
60a7b2a28d6a9229383568.png
I have a registration, I click Next and I have different content (for example, confirmation) and so at least 5 modal windows with different content, or I click Log in and another modal window opens there with another form
How to manage it? Tipo not to do the same 5 different open variables for all modal windows, and there if the User pressed the button, then 1open == false, 2 == true, etc.
How are modal windows managed in React?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2021-05-21
@maxemga

const [window, setWindow] = useState()
switch (window) {
    case 'window1':
        return <Modal1></Modal1>
    case 'window2':
        return <Modal2></Modal2>
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question