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

183
Vistas
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 Respuestas
Responde la pregunta

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 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