I am trying to develop the cleanest way to load the initial state of my Redux stores when it comes from API calls.
I understand that a typical way to provide the initial state is to create its server part when loading the page and provide it in Redux createStore () as a simple object. However, I am writing an application that I plan to package in Electron, and therefore this will not work.
So far, the best I've been able to come up with is to launch an action immediately after creating the repository, which will go and request the initial state for the repository - either one action that retrieves the entire initial state, or the number of actions, each of which returns the initial state for one parts of the repository. This would mean that my code looks like this:
const store = createStore(reducer, Immutable.Map(), middleware);
store.dispatch(loadStateForA());
store.dispatch(loadStateForB());
store.dispatch(loadStateForC());
While this will work, it seems like a bit of a rough side, and so I wonder if there is any better alternative that I am missing?
source
share