In nextjs, pathname is not an object
Change
const { pathname } = usePathname();
To
const pathname = usePathname();