SetState method is not working
See original GitHub issueI’m using the setState method but it seems it doesn’t work. actually, always the state value is equal to the default value!
this.setState(
{ currentUser: loggedInUser },
UserStoreActions.userLoggedIn
);
after setState when I’m subscribing to my state class state value is always equal to the default value!!
constructor(private authService: AuthService) {
this.subs.sink = this.authService.stateChanged.subscribe((state) => {
console.log('user panel sate', state);
this.user = state.currentUser ?? null;
});
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Why does calling react setState method not mutate the state ...
setState () does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially ...
Read more >Why my setState doesn't work? - Sergey Stadnik
setState operation is asynchronous in React. If you new state depends on the values of the old state, you should use a functional...
Read more >Why does setState() not work in my React app? - Medium
Whenever state needs to be calculated based on a previous state, it's unsafe to pass an object to setState () . Because this.state...
Read more >ReactJS setState() - GeeksforGeeks
setState is asynchronous call means if synchronous call get called it may not get updated at right time like to know current value...
Read more >React Error: "this.setstate is not a function" - How to Fix
However, when we click it, we get an error. We'll get something like “this.setState is not a function” or “cannot read property 'setState'...
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
No problem. Sorry I don’t have that feature now. I doubt it’ll ever be in the core package but could potentially be an add-on package some day.
Thank you @DanWahlin I confess that you reply very quickly and it was very awesome for me! hope to provide that part for the package very soon