I am currently working on an app that has a side menu, capable of opening and closing. By default I want it to be open so that new users can take note of its use and find their way around, but they have the option to close it for more space or when they get comfortable. Once it is closed, and the page is refreshed, I don't want it to be open again, but I want the menu to be closed. To do so, I was thinking of saving the menu state in localStorage and grabbing the value to initialize the menu.
I know with conventional react you can simply use localStorage like this
const isMenuOpen = Boolean(JSON.parse(localStorage.getItem("menu-open") || "true"));
In remix however I know localStorage can only be used in a useEffect hook.
const [isMenuOpen, setIsMenuOpen] = React.useState(true);
React.useEffect(() => {
const menuState = Boolean(JSON.parse(localStorage.getItem("menu-open") || "true"));
setIsMenuOpen(menuState);
}, []);
This leads to the menu being initialized as open, before changing to close (in the case described above). The UI experience is not the best. Is there a way to simply initialize the side menu state using the value in localStorage?