question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set the initial state?

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DanWahlincommented, Apr 7, 2020

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!

1reaction
DanWahlincommented, Apr 7, 2020

You’ll want to use the ObservableStore.initalizeState() static function:

https://github.com/DanWahlin/Observable-Store/blob/master/README.md#store-api

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found