diff --git a/docs/src/components/ReactExample/Example.tsx b/docs/src/components/ReactExample/Example.tsx index 00caae4b24..56df447f77 100644 --- a/docs/src/components/ReactExample/Example.tsx +++ b/docs/src/components/ReactExample/Example.tsx @@ -179,7 +179,6 @@ const Example = ({ restoreLocalStorage(); setPlaygroundOpened(false); setOpenEditor(true); - updateLocalStorage(defaultCode); }} knobs={exampleKnobs.length > 0} variants={exampleVariants} diff --git a/docs/src/hooks/useSandbox.ts b/docs/src/hooks/useSandbox.ts index 09af61f141..6dda8052ed 100644 --- a/docs/src/hooks/useSandbox.ts +++ b/docs/src/hooks/useSandbox.ts @@ -1,18 +1,9 @@ import React from "react"; -import { load, save } from "../utils/storage"; +import { save } from "../utils/storage"; const useSandbox = (exampleId: string, initialCode: string) => { - const [code, setCode] = React.useState(() => { - try { - const storedCode = load(exampleId); - return storedCode || initialCode; - } catch (err) { - console.error(err); - return initialCode; - } - }); - + const [code, setCode] = React.useState(initialCode); const [origin, setOrigin] = React.useState(""); React.useEffect(() => { @@ -23,6 +14,10 @@ const useSandbox = (exampleId: string, initialCode: string) => { setCode(e.newValue); } }); + + return () => { + window.removeEventListener("storage", () => {}); + }; }, [exampleId]); const updateLocalStorage = (newCode: string) => {