useMemo hook always True even the location.pathname change
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]);