Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda