Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there something like persistGate from redux-persist? #61

Open
railanxisto opened this issue Nov 6, 2018 · 2 comments
Open

Is there something like persistGate from redux-persist? #61

railanxisto opened this issue Nov 6, 2018 · 2 comments

Comments

@railanxisto
Copy link

railanxisto commented Nov 6, 2018

Hi everyone.

I am having an issue now that is my component renders before the store is fully hydrated.
If I use a setTimeout with like 1 second it works but this is just a bad workaround.

Is there something like PersistGate (https://github.com/rt2zz/redux-persist) in mobx-persist or does anyone have an idea how to implement something like that?

Thanks in advance

@lxblink
Copy link

lxblink commented Nov 6, 2018

@railanxisto Try this:

When hydrate your store, you can call anything on success:

hydrate('store', yourStore)
    .then(() => yourStore.setIsReady(true));

In store:

class AppStore {
  @observable isReady= false;
  @action setIsReady = value => this.isReady = value;
}

And then you can use something like this in your component:

@inject(({ store }) => ({
  isReady: store.isReady,
}))
class YourApp extends Component {
  render() {
    return this.props.isReady && (
      <YourComponent />
    );
  }
}

@railanxisto
Copy link
Author

Thanks @lxblink . I implemented something like that on my root component and it works like a charm without a need for the setTimeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants