Skip to content

Save the state/layout of an edited page #205

Closed Answered by strictlylucian
strictlylucian asked this question in Q&A
Discussion options

You must be logged in to vote

Sort of dug some more and found the answer for anyone interested, saving the layout with localStorage with functional React goes something like this (can probably be improved)

    const [mosaicState, setMosaicState] = useState(null);

    useEffect(() => {
        if(!localStorage.getItem('layout_name')) return setMosaicState(some_initial_state)
        setMosaicState(JSON.parse(localStorage.getItem('layout_name')))
    }, []);

    useEffect(() => {
        if(mosaicState) localStorage.setItem("layout_name", JSON.stringify(mosaicState));
    }, [mosaicState]);
    
    ...

    <Mosaic
        renderTile={(id, path) => (
            ....
        )}
        onChange={node => setMosaicState(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by strictlylucian
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants