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

299
Views
React - Accessing data from child component without rendering child component

I am trying to access data within a deeply nested child component by passing a callback function from the parent component through various child components.

For example, say that this is the parent component that I am rendering:

function ParentComponent = () => {
  const [data, setData] = useState();
  
  const callback = (obj) => {
    setData(obj);
  }
  
  return <p>{data}</p>
}

And I am trying to retrieve data from the nested component in a different file:

// I need to call this component somehow from the parent component
function InitialChildComponent = ({cb}) => {
  return <NestedChildComponent cb={cb}/>
}

// this component cannot directly be called from ParentComponent
function NestedChildComponent = ({cb}) => {
  let data = 'abc';
  cb(data);
  
  return <p> don't want this displayed </p>
}

Is there any way to run the callback function from within the nested child component without displaying the JSX in that same nested component? Or is there another better method of accessing this data from the nested child component?

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!