Configuration

In your app's main module, register store with initial state by using ReactState.Init with with initial state object as a first variable and value for identifying is it prod environment as second parameter.

Immer

ReactState
.addDataStrategy(ImmerDataStrategy)
.init((routerHistory: History) => {
    ReactDOM.render(<Main history={routerHistory} />, document.getElementById("example"))
}, initialState)

ImmutableJs

ReactState
.addDataStrategy(ImmutableJsDataStrategy)
.init((routerHistory: History) => {
    ReactDOM.render(<Main history={routerHistory} />, document.getElementById("example"))
}, initialState)

where initial state looks like

export const initialState = {
    todos: <any[]>[],
    storage: {
        itemToStore: 'some value'
    },
    form: {
        condition: {
            new: true,
            used: false,
            notSpecified: false,
        },
        location: 'europe',
    }
};

In addition you can pass other variables to StoreModule.provideStore function

  • enableSSR- makes routing compatible with SSR

  • collectHistory - should history be collected at all - default is true

  • storeHistoryItems - how many items should be stored. Default is 100

Last updated