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

263
Visualizações
Access Hook (and All functions of a hook) from a parent component without passing functions down?

I am writing a sandbox testing environment for a complex component (Labeler) in our codebase. The complex component uses a large hook to manage state right now (LabelerHook), and the hook as specific functions I want to be able to use for sandbox testing. I have a working version, but it's very clunky.

Right now, I have a page that is the sandbox passing in dummy props to the Labeler component. This works well for instantiating the component, but doesn't give me the ability to interact with the hook. To do that, I am using a window.ref to pass the hook up.

// somewhere inside labeler
window.hook = labelerHook 


// somewhere that is parent of labeler
let hook = window.hook 

However, this doesn't work well because I noticed that after rerenders of the labeler, the hook in the parent of the labeler and the hook in the labeler is not in sync. Right now, I have a "refresh" function that I have to click everytime they go out of sync.

I know there must be a better way of passing this data up, but I don't want to pass extra props into labeler because that could cause many issues and we can't move LabelerHook up either.

I've heard of people using context but I'm not sure how to use it here to pass a hook upward either?

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