Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!