V
V
Vadim Chorrny2020-11-01 13:51:19
React
Vadim Chorrny, 2020-11-01 13:51:19

How to properly make a module window in React?

Hello!
I have a modular window and I made it a component (in a separate file), when you click on the div element, you need to show this window.
( I have a module window in one file, a div element in another )
How to do it right I have two guesses:
1) Make the modal and div in the same file ( cons: bad code, styling problems )
2) Use React-Route ( I don't even know how to use it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2020-11-01
@Chorrny

Like this:

const [modalIsVisible, setModalIsVisible] = useState(false);

return (
  <>
    <button onClick={() => setModalIsVisible(true)}>Show modal</button>
    { modalIsVisible && <Modal onClose={() => setModalIsVisible(false)} /> } 
  </>
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question