Persist store throughout page reloads
See original GitHub issueWhat problem is this solving
To completely eliminate the need for Vuex, since Vuex has session persistence support via a plugin.
Proposed solution
Accept an extra object in the createStore initialization:
export const usePiniaStore = createStore({
id: "simpleStore",
state: () => ({
simpleVariable: "",
}),
persistence: {
enable: true,
mode: "localSession"
}
});
// type definition
interface IPiniaPersistence {
enable: boolean,
mode: "localSession" | "localStorage";
}
Describe alternatives you’ve considered
There does not seem to be any Vuex-less alternatives out there that supports the vue-composition-api.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How can I persist redux state tree on refresh? - Stack Overflow
If you would like to persist your redux state across a browser refresh, it's best to do this using redux middleware.
Read more >5 Methods to Persisting State Between Page Reloads in React
One of the straightforward options is to use localStorage in the browser to persist the state. Let's take a look at an example....
Read more >React Redux Persist State on refresh || Keep the user logged in
Today we shall learn how to persist the redux state on page refresh or Keep the user logged in. React Redux tutorial: ...
Read more >How to Save State to LocalStorage & Persist on Refresh with ...
I've preloaded the application with some data from spacejelly.dev where at that point I'm simply looping through each post and rendering them on ......
Read more >Persist store throughout page reloads · Issue #309 · vuejs/pinia
What problem is this solving To completely eliminate the need for Vuex, since Vuex has session persistence support via a plugin. Proposed solution...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
An updated and simpler version is to use something like https://vueuse.org/core/uselocalstorage/#uselocalstorage:
Vuex doesn’t have persistence support, it comes from a plugin. For Pinia, it would be the same. This can be implemented by using
astore.$subscribe
watch(pinia.state, handler, { deep: true })
to write to local storage (or anything else) and watching localStorage for changes and writing back to the store.Something along the lines of
You can inspire yourself from https://github.com/robinvdvleuten/vuex-persistedstate/blob/master/src/index.ts to create it
There is also https://github.com/posva/pinia/issues/191 going on to discuss plugins, they will probably be similar to Vuex 5 plugins once that is discussed too