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.

Bug: useReducer runs the queued updates with new props

See original GitHub issue

React version: 16.8.0

Steps To Reproduce

Link to code example: https://codesandbox.io/s/usereducer-wfcmq Link to codesandbox.

The current behavior

Initially step is 0. So for every step react does not rerender due to this https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberHooks.js#L1347. But state updates are queued. So when step changes all the state updates are done and hence creates a bug by adding the new step prop.

https://overreacted.io/a-complete-guide-to-useeffect/#why-usereducer-is-the-cheat-mode-of-hooks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Mar 17, 2020

I think it’s a bug.

0reactions
zxh19890103commented, Jul 10, 2021

mark.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React useReducer ignores state updates if executed fastly?
If the promise is rejected, the rollback is executed, updating the UI to the previous state. What I don't understand is why if...
Read more >
Hooks API Reference - React
The setState function is used to update the state. It accepts a new state value and enqueues a re-render of the component. setState(newState);....
Read more >
React useReducer Hook ultimate guide - LogRocket Blog
The useReducer Hook is used to store and update states, just like the useState Hook. It accepts a reducer function as its first...
Read more >
React State Management With useReducer
Like useState and useContext , useReducer is a new twist on a ... Reducers are functions that help us update state based on...
Read more >
React Hooks - A deeper dive featuring useContext and ...
If you're brand new to React hooks, check out the Primer on React Hooks ... YET - just prop smuggling import React, {...
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