Skip to content

Commit

Permalink
fix: resolve error on SSR with document (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien-Ahkrin committed Mar 30, 2022
1 parent 1fa2e72 commit 08869d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/layout/RootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const style: CSSProperties = {
};

export function RootLayout(props: RootLayoutProps) {
const [state, setState] = useState<HTMLElement>(document.body);
const [state, setState] = useState<HTMLElement | null>(
typeof document !== 'undefined' ? document.body : null,
);

const ref = useCallback((node: HTMLDivElement) => {
if (node !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/layout/context/RootLayoutContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useRootLayoutContext() {

export function RootLayoutProvider(props: {
children: ReactNode;
innerRef: HTMLElement;
innerRef: HTMLElement | null;
}) {
return (
<rootLayoutContext.Provider value={props.innerRef}>
Expand Down

0 comments on commit 08869d0

Please sign in to comment.