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

94
Vistas
React - Object field as dependency of useMemo

I have the following code:

   const iconMap = useMemo(() => ({
     HomeStacks: {
       iconName: "home",
       iconType: "material-community",
     },
     ActivityStacks: {
       iconName: "bell",
       iconType: "material-community",
       badgeCount: badges["activity"],
     },
   }), [badges["activity"]]);

And, for some reason, ESLint is throwing me an error from the rule "react-hooks/exhaustive-deps":

React Hook useMemo has a missing dependency: 'badges'. Either include it or remove the dependency array. eslintreact-hooks/exhaustive-deps

So, is it not valid to use object fields as dependencies?

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

0

It definitely is, but eslint appears to be confused by the bracket notation accessor. In newer versions of react-hooks/exhaustive-deps it is perfectly fine to use dot notation in the dependency list, but for any use cases where it will complain, you can always extract the property to a constant above the dependency list like so (assuming you do not want to suppress the warning):

 const activity = badges["activity"];
 const iconMap = useMemo(() => ({
     HomeStacks: {
       iconName: "home",
       iconType: "material-community",
     },
     ActivityStacks: {
       iconName: "bell",
       iconType: "material-community",
       badgeCount: activity,
     },
   }), [activity]);
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