Skip to content

Commit dabf873

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

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/Editor.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ 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(defaultValue);
9+
useEffect(() => {
10+
const currentValue = localStorage[key];
11+
if (currentValue != null) {
12+
setState(currentValue);
13+
}
14+
}, [key]);
915
useEffect(() => {
1016
if (state != null && key != null) {
1117
localStorage[key] = state;

0 commit comments

Comments
 (0)