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

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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