Skip to content

Commit

Permalink
feat: pass content prop into Playground (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyanovandrey authored Sep 19, 2023
1 parent 39e32bd commit 68eb23c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ const App = () => {
};

export type PlaygroundProperties = {
content?: string;
persistRestore?: boolean;
}

function Playground(props: PlaygroundProperties) {
const persist = useCallback(persistRestore.persist, []);
const restore = useCallback(persistRestore.restore, []);
const [input, setInput] = useState(props.persistRestore ? (restore() ?? '') : '');
const content = props?.persistRestore ? restore() : props?.content
const [input, setInput] = useState(content ?? '');
const [generated, setGenerated] = useState(input);

const generate = useCallback((active: string) => {
Expand Down Expand Up @@ -86,7 +88,7 @@ function Playground(props: PlaygroundProperties) {
useEffect(() => {
generate(outputActive);

if (props.persistRestore) {
if (props?.persistRestore) {
persist(input);
}
}, [input]);
Expand Down

0 comments on commit 68eb23c

Please sign in to comment.