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

105
Vistas
useMemo hook always True even the location.pathname change

I am trying to render a specific Layout if the location change and I'm using the useMemo hook to validate the route and render the based on this value but it always returns true even the route change for example the new route is .../SSDSD/draft

const location = useLocation();
  console.log(location)
  const showShadow = useMemo(() => ['preview', 'signing', 'receipts'].some(word => location.pathname.includes(word)), [location]);
  const isHomePage = useMemo(() => ['/', '/search', '/addressbook'].some(word => location.pathname.includes(word)), [location]);
  console.log(isHomePage);
  //debugger;
  return (
    <ThemeProvider theme={theme}>
      <Box className={isHomePage ? classes.homeBackground : classes.innerBackground}>
      </Box>
    </ThemeProvider>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is that you include "/" in the array. location.pathname always begins with a "/", so this will always be true.

const result = ['/', 'any string', 'any other string', 'doesnt matter'].some(str => location.pathname.includes(str));
console.log(result); // always true

Instead, you probably want to include all pathnames which actually represent your "homepage" and use str.startsWith instead of str.includes, using something like this:

const isHomePage = useMemo(() => (
  location.pathname === '/'
  || ['/search', '/addressbook'].some(str => location.pathname.startsWith(str))
), [location]);
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