Can't set state in use hook
See original GitHub issueExpected behavior
When seting state like this
app.use(function (state) {
state = {
a: 'some',
b: 'value'
}
})
then, the state should be able to access props like state.a
and state.b
Actual behavior
Above code didn’t work for me. I had to do
app.use(function (state) {
state.a = 'some'
state.b = 'value'
})
Steps to reproduce behavior
Run the above code, I haven’t any repo yet, but if needed I will have one tomorrow 😉
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
javascript - React State Hook - I can't set state - Stack Overflow
This is a bad practice. We shall use the setState callback when merging data to state. · @IanVasco You don't always need to...
Read more >React setState does not immediately update the state - Medium
useState React hook Returns a stateful value, and a function to update it. The function to update the state can be called with...
Read more >Using the State Hook - React
There are some special rules about where you can and can't use Hooks within a component. We'll learn them in Rules of Hooks....
Read more >Why React setState/useState does not update immediately
React setState and useState are asynchronous actions. React setState and useState only create queues for React core to update the state of React...
Read more >React hooks gotchas: setState in async useEffect
Important note:This happens only with async actions (aka promises in useEffect ). When a useEffect() does not trigger any async action, the 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
Yay, happy to help!
On Thu, Aug 10, 2017, 14:45 Yerko Palma notifications@github.com wrote:
@rafaelamorim