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

180
Visualizações
How to use react hooks inside of HOC component?

I have a problem making a HOC component with hooks inside.

I am trying to find a correct solution to not break rules-of-hooks.

If I change the name of this component to start with lowercase: withNetworkDetector instead of uppercase, I will not get errors, but did I break the rule then?

Is this code will be secure then?

export const WithNetworkDetector = (Component: FC<{}>) => (props: any) => {
  const [isDisconnected, setIsDisconnected] = useState(false);

  const handleConnectionChange = useCallback(() => {
   ...
    setIsDisconnected(true);
  }, []);

  
  return (
    <div>
      {isDisconnected && (
          <Toast type="warning" text={TOAST_ERRORS.LOST_INTERNET_CONNECTION} />
      )}
      <Component />
    </div>
  );
};

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hooks can be used inside the React functional component. One of the criterias that classify a function as a react function is the name starting in uppercase, then only we can use that as a React component. So, it will break the rule.

about 4 years ago · Juan Pablo Isaza 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