Skip to content

Commit

Permalink
fix(react): use current pathname when rendering (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVidra authored Feb 4, 2025
1 parent d476278 commit 04c0610
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions workspaces/react/src/contexts/pathname-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type ReactNode,
} from "react";

const INTERVAL_MS = 250;
const INTERVAL_MS = 200;

const _usePathname = (): string | undefined => {
const [pathname, setPathname] = useState<string>();
Expand All @@ -38,7 +38,12 @@ const _usePathname = (): string | undefined => {

type IPathnameContext = string | undefined;
const PathnameContext = createContext<IPathnameContext>(undefined);
export const usePathname = (): IPathnameContext => useContext(PathnameContext);
export const usePathname = (): IPathnameContext => {
const contextValue = useContext(PathnameContext);
// Avoid accessing window on the server
if (contextValue === undefined) return;
return getPathname();
};

interface Props {
children?: ReactNode;
Expand Down

0 comments on commit 04c0610

Please # to comment.