diff --git a/src/lib/ScrollReset.client.tsx b/src/lib/ScrollReset.client.tsx index e8d2fde..bb17cd8 100644 --- a/src/lib/ScrollReset.client.tsx +++ b/src/lib/ScrollReset.client.tsx @@ -1,7 +1,7 @@ -import { useLayoutEffect } from "react"; +import { useClientLayoutEffect } from "./utils"; export function ScrollReset() { - useLayoutEffect(() => { + useClientLayoutEffect(() => { document.querySelector("#root > div")?.scrollTo({ top: 0, behavior: "smooth" }); }); return null; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d666934..d9c85cc 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,4 +1,7 @@ +import { useEffect, useLayoutEffect } from "react"; + export type Color = "matcha" | "walnut" | "pepper" | "grain"; export type MakePropertiesOptional = T extends T ? Omit & Partial> : never; +export const useClientLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;