Save the state/layout of an edited page #205
-
Hey yall, Hopefully this isn't a silly question that I've obliviously missed the answer for in the docs, but is there any way to save the state of a modified Mosaic component once a user interacts with it (say export it and save it in some fashion)? I'm currently building an app where saving such state would be quite useful. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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(node)}
value={mosaicState}
/> |
Beta Was this translation helpful? Give feedback.
-
? |
Beta Was this translation helpful? Give feedback.
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)