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

276
Vistas
NextJS - build fails even though dev runs fine, complaining about React Hooks where I'm not using them

first-time poster here. I'm pretty new to React & JS in general, and I've been working in NextJS. Interestingly, my project runs just fine when I run next dev, but fails when I use next build.

I get the following error:

Error: React Hook "useFunction" 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

What's interesting about useFunction is that it is not a Hook - I define it as a function in the same file as a component FunctionButton like so and use it as part of the onClick event handler

const useFunction = async () => {

  const result = await someStuff();
  return result

}


const FunctionButton = () => {
  return <Button onClick={() => useFunction()}>Click Me</Button>;
};

export default FunctionButton;

Any idea why this isn't building successfully? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The reason that it thinks useFunction is a hook is because that's how React's linting checks work. They rely on the use prefix to determine that it's a hook:

We provide an ESLint plugin that enforces rules of Hooks to avoid bugs. It assumes that any function starting with ”use” and a capital letter right after it is a Hook.

So, merely because your function starts with use, React takes it to be a hook. A solution would be to rename your function or add an eslint-ignore comment.

about 4 years ago · Juan Pablo Isaza Denunciar

0

React considers the files whose name starts with the word use as hooks even though they aren't.

There are to ways to solve the issue:

  1. simply rename your file. (does not start with use)
  2. add /* eslint-disable */ block comment at the top of the file.
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