import {usePathname} from "next/navigation";
...
export default function Layout({children}) {
const currPathname = usePathname();
const visitorParams: VisitorQueryProviderProps = {
apiKey : process.env.NEXT_PUBLIC_VISITOR_QUERY_API_KEY as string,
sessionId: getSetVisitorId(true),
endpoint : process.env.NEXT_PUBLIC_VISITOR_QUERY_ENDPOINT as string || undefined,
};
const [pathname, setPathname] = React.useState(currPathname);
useEffect(() => {
if (pathname != currPathname) {
setPathname(currPathname);
}
}, [currPathname]);
return (
// notice the `trigger` prop being passed
<VisitorQueryProvider {...visitorParams} trigger={pathname}>
{children}
</VisitorQueryProvider>
);
}