Skip to content

Commit 8191339

Browse files
committed
Remove SSR warning
1 parent 059c384 commit 8191339

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/mini-editor/src/use-snapshots.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { Snapshot, TabsSnapshot } from "./editor-frame"
33

44
export { EditorStep, StepFile, useSnapshots }
55

6+
const useLayoutEffect =
7+
typeof window !== "undefined"
8+
? React.useLayoutEffect
9+
: React.useEffect
10+
611
type StepFile = {
712
code: string
813
focus?: string
@@ -39,7 +44,7 @@ function useSnapshots(
3944
nextSnapshot: null,
4045
})
4146

42-
React.useLayoutEffect(() => {
47+
useLayoutEffect(() => {
4348
if (prevSnapshot || nextSnapshot) {
4449
setState({
4550
prevSnapshot: null,
@@ -48,7 +53,7 @@ function useSnapshots(
4853
}
4954
}, [prev, next])
5055

51-
React.useLayoutEffect(() => {
56+
useLayoutEffect(() => {
5257
if (!prevSnapshot) {
5358
setState(s => ({
5459
...s,

0 commit comments

Comments
 (0)