We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6ef94b2 commit dabf873Copy full SHA for dabf873
components/Editor.js
@@ -5,7 +5,13 @@ import { CodeSandbox } from "./CodeSandbox";
5
const Editors = { Glitch, CodeSandbox };
6
7
export const useLocalStorage = (key, defaultValue) => {
8
- const [state, setState] = useState(() => localStorage[key] ?? defaultValue);
+ const [state, setState] = useState(defaultValue);
9
+ useEffect(() => {
10
+ const currentValue = localStorage[key];
11
+ if (currentValue != null) {
12
+ setState(currentValue);
13
+ }
14
+ }, [key]);
15
useEffect(() => {
16
if (state != null && key != null) {
17
localStorage[key] = state;
0 commit comments