Data Fetching, Store and LocalStorage
Hello friends,
I am trying to understand the store lifecycle, but I have yet to find a good article / document on the topic.
I understand that there is data fetching from the server and from the client.
I was originally planning to set up a store and initializing some state from the server, for website often-updated data with usefetch server true, and some persitent data with a mix of usefetch server false and localstorage.
My issue is that I cannot control when the state is set up, and so localstorage and client side state initialization fails unless I use some kind of onMounted, getCurrentInstance and process.server shenanigans.
I want control when the state is set up, because at the moment I just get an empty {} : the state try to initialize once, fails which is normal cause SSR.
Should I just trigger some actions from the client ? This seems like a lot of boilerplate.
Any relevant resource or document ?
Is there a way to control when the store is set up ?
How would you approach this kind of thing ?
I was trying to keep things simple because all that's needed is a nicely timed localstorage getitem and setitem, but maybe I should look into some persisted state plugin.
Thank you very much for your help, insight and time
I am trying to understand the store lifecycle, but I have yet to find a good article / document on the topic.
I understand that there is data fetching from the server and from the client.
I was originally planning to set up a store and initializing some state from the server, for website often-updated data with usefetch server true, and some persitent data with a mix of usefetch server false and localstorage.
My issue is that I cannot control when the state is set up, and so localstorage and client side state initialization fails unless I use some kind of onMounted, getCurrentInstance and process.server shenanigans.
I want control when the state is set up, because at the moment I just get an empty {} : the state try to initialize once, fails which is normal cause SSR.
Should I just trigger some actions from the client ? This seems like a lot of boilerplate.
Any relevant resource or document ?
Is there a way to control when the store is set up ?
How would you approach this kind of thing ?
I was trying to keep things simple because all that's needed is a nicely timed localstorage getitem and setitem, but maybe I should look into some persisted state plugin.
Thank you very much for your help, insight and time
