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

300
Visualizações
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
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