Skip to content

Commit

Permalink
docs: remove persistance of code in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
mainframev committed Jan 17, 2024
1 parent 040f1d2 commit f76ffdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
1 change: 0 additions & 1 deletion docs/src/components/ReactExample/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ const Example = ({
restoreLocalStorage();
setPlaygroundOpened(false);
setOpenEditor(true);
updateLocalStorage(defaultCode);
}}
knobs={exampleKnobs.length > 0}
variants={exampleVariants}
Expand Down
17 changes: 6 additions & 11 deletions docs/src/hooks/useSandbox.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -23,6 +14,10 @@ const useSandbox = (exampleId: string, initialCode: string) => {
setCode(e.newValue);
}
});

return () => {
window.removeEventListener("storage", () => {});
};
}, [exampleId]);

const updateLocalStorage = (newCode: string) => {
Expand Down

0 comments on commit f76ffdc

Please sign in to comment.