Sometimes it can be useful to provide initialState later, using setInitialState.
Especially when managing local component state:
Imagine the initial state depends on component Inputs / props.
const fs = new FeatureStore<TodosState>('test', undefined); // Set undefined explicitly as initial state
const fsState$ = fs.select();
fsState$.subscribe((v) => console.log('# test', v));
// Test lazy initialization
setTimeout(() => {
fs.setInitialState(initialState); // Provide initial state later
}, 5000);
setTimeout(() => {
// Use setState as usual
fs.setState({
todos: [{ id: 123, title: 'test', isDone: false }],
});
}, 6000);
Sometimes it can be useful to provide initialState later, using
setInitialState
. Especially when managing local component state: Imagine the initial state depends on component Inputs / props.