Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
gancho useMemo siempre verdadero incluso el cambio de ubicación.nombre de la ruta

Estoy tratando de representar un diseño específico si la ubicación cambia y estoy usando el enlace useMemo para validar la ruta y representarla en función de este valor, pero siempre devuelve verdadero, incluso el cambio de ruta, por ejemplo, la nueva ruta es .../ SSDSD/borrador

 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 answers
Answer question

0

El problema es que incluye "/" en la matriz. location.pathname siempre comienza con "/" , por lo que siempre será cierto.

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

En su lugar, probablemente desee incluir todos los nombres de ruta que realmente representan su "página de inicio" y usar str.startsWith en lugar de str.includes , usando algo como esto:

 const isHomePage = useMemo(() => ( location.pathname === '/' || ['/search', '/addressbook'].some(str => location.pathname.startsWith(str)) ), [location]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!