How to set the initial state?
See original GitHub issueHi Dan,
In the current version, the state is null/undefined until the state is set. What’s the best way to set an initial state for a store?
Right now I’m doing this:
constructor() {
this.setState({}, 'INITIALIZE_STATE');
}
However, I’m not sure this is semantically correct or just a workaround. Feels wrong somehow, because there was no action triggered - it’s just the state being initialized (not an action imho).
Maybe a setInitialState
or initializeState
method is necessary.
constructor() {
this.setInitialState({});
}
Or maybe in the super constructor since initializing state would be done only once?
constructor() {
this.super({});
}
However, that is already used for the config/settings…
Any thoughts on this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
how to set initial state in redux - reactjs - Stack Overflow
I'm trying to figure out how to set an initial state for a store in redux. I'm ...
Read more >How to set initial state in Redux ? - GeeksforGeeks
Step 4: In src folder, make two new folder components and redux. In components add two jsx files named content.jsx and header.jsx. In...
Read more >HOW TO PROPERLY SET INITIAL STATE IN REDUX
1. Initializing State. In Redux, all your application state is held in the store; which is an object that holds the complete state...
Read more >Initial state - MATLAB & Simulink - MathWorks
Simulink ® software loads initial states from a workspace. Specify the name of a variable that contains the initial state values, for example,...
Read more >Learn: Initial State 101
Getting Started with Initial State. Quickly get up and running with your Initial State account. Learn the basics of how to stream data...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sound great. I’m super open to feature ideas (many have come from other people using it) so if you do think of something and it still keeps things simple let me know. Appreciate it!
You’ll want to use the ObservableStore.initalizeState() static function:
https://github.com/DanWahlin/Observable-Store/blob/master/README.md#store-api