Answer the question
In order to leave comments, you need to log in
How to keep store in react mobx even on page reload?
I tried to use this solution, which saves the store at a certain time interval, but for some reason a new element does not appear in localstorage.
const store = observable({
players: [
"Player 1",
"Player 2",
],
// ...
})
reaction(() => JSON.stringify(store), json => {
localStorage.setItem('store',json);
}, {
delay: 500,
});
let json = localStorage.getItem('store');
if(json) {
Object.assign(store, JSON.parse(json));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question