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

150
Visualizações
Trigger event from child to parent, {children}

I want to trigger a modal event from the children component. Usally I pass the state in form of <Children handleOpen={HandleOpen} />. If the button get pressed in the children component, the event inside the parent should be triggerd and show the text from the children. How can I realize that if {children} is in use?

app.js

const App = () => {
  return (
      <Router>
        <div>
          <Switch>
          <PrivateRoute exact path="/children1" component={children1} layout={basic} />
          <PrivateRoute exact path="/children2" component={children2} layout={basic} />
          </Switch>
        </div>
      </Router>
  );
}

Layout Wrapper/Parent/Basic

const Basic = ({children}) => {
    //Modal
    const [open, setOpen] = React.useState(false);
    const handleOpen = () => setOpen(true);
    const handleClose = () => setOpen(false);

    return (
      <div className="App">
        //Insert Children Component
        {children}

        //Show this Modal when called from children/with sent data
        <Modal open={open} onClose={handleClose}>
         <Box>
          data xxx from child
         </Box>
        </Modal>
      </div>
    );
  };

children1 & children2

const children1 = ( { handleOpen }) => {
    return (
      <div>
        <button onClick={handleOpen} data={xxx}>Open Modal with xxx Text</button>
      </div>
    );
  };
about 4 years ago · Juan Pablo Isaza
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