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

184
Visualizações
Next JS Higher Order Component Error During Build Time

I have a Next JS application, and for authentication, I have used higher-order component to check auth status automatically. And my code works fine locally but when I run npm run build then it's giving me this error error Error: Component definition is missing display name react/display-name 6:27 Error: React Hook "useSession" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function. react-hooks/rules-of-hooks

here is my code on GitHub

Auth.tsx

AuthProvider

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

0

Your problem is due to Auth name which is considered as a component name. It should be a camel-cased name like auth or withAuth.

You can check the logic below

import { useEffect } from "react"
import { useRouter } from "next/router";
const withAuth = (Component: any) => {
  const {auth, loading} = useSession();
      const router = useRouter();
      useEffect(() => {
        console.log('use effect')
        if(!loading && !auth.auth) {  
          router.push('/login')
        }
      }, [auth,loading])
     
     const ComponentWrapper = (props: any) => auth.auth && <Component {...props} />  

     return <ComponentWrapper/>
}

export default withAuth

Usage in components

withAuth(Component)
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