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

114
Vistas
HOC inside react hook, causes infinite rerenders

Im attempting to return a HOC component from within the hook.

Let's say I have a top level component as...

function Component(props){
  //do something with props;
  return <h1>Hello {props.title}</h1>
}

And a hook which knows some props, and wants to free the user from providing those props

function useHook(){
  //somehow get prop values at runtime(say title)
  const title = //get from API call;
  return (props) => <Component title={title} {...props}/>
}

Any idea why infinite rerendering happens here? Should I be using useCallback?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

React Hooks return children wrapping component

The Problem was addressed here. useCallback solved the infinite re-render. Looks like the hook was recreating the component upon every run (function reference changes upon every run, though it looks like its the same function).

function useHook(){
  //somehow get prop values at runtime(say title)
  const title = //get from API call;
  return useCallback((props) => <Component title={title} {...props}/>,[title]);
}
about 4 years ago · Santiago Gelvez Denunciar
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