Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
How to open a modal component through an onClick from another component

This question is related to this one. I am rewording to make it simple.

I have a main navigation component (MainNavigation.js) which is siblings with a Secondary Navigation Component(SecNavigation.js) under the Header component(Header.js).

What I want is when I click on a specific Link in the MainNavigation.js the whole SecNavigation.js to be displayed in a modal.

My problem here is that I don't quite grasp how should I go using useState, useContext or even if I need any of this.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hope this will clear something for you

What you need is a parent that handles the state and then it will pass it down to its children. Because the parent is keeping track of the children and what they are doing.

So what I have done it this:

App.js is the parent and I handle the state here. Then I just pass down the setIsModalShowing setState function to the MainNav that will call it when I press a button.

Then in the App.js I will show or hide the modal if the setIsModalShowing is true or false

inside of the modal I am showing SecNav and the modal also has the setIsModalShowing passed down so that you can click on the button to close is and that will set the state to false.

Does that makes sense to you ? or else I can try to explain it in another way

Code example

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda