Skip to content

Commit

Permalink
useLayoutEffect only on client
Browse files Browse the repository at this point in the history
  • Loading branch information
futurGH committed Nov 2, 2023
1 parent 7bf1519 commit 380e993
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/ScrollReset.client.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useEffect, useLayoutEffect } from "react";

export type Color = "matcha" | "walnut" | "pepper" | "grain";
export type MakePropertiesOptional<T, K extends string> = T extends T
? Omit<T, K> & Partial<Pick<T, K extends keyof T ? K : never>>
: never;
export const useClientLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;

0 comments on commit 380e993

Please sign in to comment.