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.

Can't set state in use hook

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
yoshuawuytscommented, Aug 10, 2017

Yay, happy to help!

On Thu, Aug 10, 2017, 14:45 Yerko Palma notifications@github.com wrote:

It makes sense, thanks for the answer.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/choojs/choo/issues/544#issuecomment-321540443, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWletj7XVHt5_kHYjBVp3tV3cm7tIgbks5sWvtagaJpZM4OytkQ .

0reactions
bcomnescommented, Aug 10, 2017

@rafaelamorim

  • To use immutable, I believe you can just assign immutable objects to properties of state, and then have your components use that.
  • Barracks still exists https://github.com/yoshuawuyts/barracks. I would love to see an example of someone hooking it up to Choo 6. I haven’t tried it yet.
Read more comments on GitHub >

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

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