pinqy520 / mobx-persist

persist mobx stores
MIT License
560 stars 62 forks source link

usage with react can cause race conditions with computed properties derived from persisted value #43

Open r3wt opened 6 years ago

r3wt commented 6 years ago

here is how i had to solve it, by not mounting the app until store was hydrate.

import App from './App';
import store from './Store';//herre is where persist is imported and applied as necessary.
import { create } from 'mobx-persist';
const storeName='foobar';

create()(storeName,store).then(()=>{
    ReactDOM.render(
        <App store={store} />
        , document.getElementById('root'));    
    setTimeout(()=>registerServiceWorker)
});

this is dangerous because computed properties don't cause rerenders in mobx. if this is a bug in mobx instead, feel free to notify them.

designbyadrian commented 6 years ago

I agree. I can't figure out when you should call hydrate?

I've got a few components that call the stores from componentWillMount, but there is no example of how to mix that with hydrate.

MrGurns commented 6 years ago

I believe you want to rehydrate the data everytime it is updated, but i'm not entirely sure yet.