Skip to content

Commit 0c097e4

Browse files
committed
fix: Don't use localStorage in SSR
1 parent 6ef94b2 commit 0c097e4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

components/Editor.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { CodeSandbox } from "./CodeSandbox";
55
const Editors = { Glitch, CodeSandbox };
66

77
export const useLocalStorage = (key, defaultValue) => {
8-
const [state, setState] = useState(() => localStorage[key] ?? defaultValue);
8+
const [state, setState] = useState(
9+
() =>
10+
typeof localStorage !== "undefined" || (localStorage[key] ?? defaultValue)
11+
);
912
useEffect(() => {
1013
if (state != null && key != null) {
1114
localStorage[key] = state;

0 commit comments

Comments
 (0)