Ignite React Native Boilerplate Mobx State Tree initialize state

656 Views Asked by At

I am coming from redux and would like to change to the ignite boilerplate.

I have a boilerplate specific question: How do I initiliaze a store with an initialstate in Mobx?

I know how it conceptually works with creating an instance, but can't see a way to integrate it into the boilerplate. All I can see is the 'rehydration' from a saved state

Thanks a lot for your help!

https://github.com/infinitered/ignite/tree/master/boilerplate/app/models

1

There are 1 best solutions below

0
On

@Tholle did a good job of answering this. If I could turn his comment into an answer, I would.

Ignite will initialize the rootStore instance with what is stored in AsyncStorage. You could e.g. modify the setupRootStore function to take in an optional initial state.

https://github.com/infinitered/ignite/blob/8b6ae0bc096d2d6d5d19e3151ada66455915b104/boilerplate/app/models/root-store/setup-root-store.ts#L27-L55