-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: useReducer rendering behaviour in React 18 #26131
Comments
@hhkk28 There's a difference between v17 and v18 for the "reset" button. The v17 version is working as described in the docs (https://reactjs.org/docs/hooks-reference.html#bailing-out-of-a-dispatch):
Check out the following example: https://codesandbox.io/s/wispy-hooks-0vytuh?file=%2Fsrc%2FApp.js |
I see, now i understand the issue. According to the PR - #22445 I think this bailout behavior is removed for useReducer. |
@hhkk28 Thanks for pointing out the PR. Much appreciated! |
Does that mean this issue can be closed @mikirejf ? |
Can be closed 👍 |
|
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
import React, { useReducer } from "react";
const initialState = 0;
const reducer = (state, action) => {
switch (action) {
case "INCREMENT":
return state + 1;
case "DECREMENT":
return state - 1;
case "RESET":
return initialState;
default:
return state;
}
};
const UseReducer = () => {
const [count, dispatch] = useReducer(reducer, initialState);
console.log('UseReducer Render')
return (
<button onClick={() => dispatch("INCREMENT")}>Increment
<button onClick={() => dispatch("DECREMENT")}>Decrement
<button onClick={() => dispatch("RESET")}>Reset
);
};
export default UseReducer;
In react 17, useReducer re-render was working as same as useState does but now after updating version to 18, whenever i click reset button, console.log('UseReducer Render'); is printed
The text was updated successfully, but these errors were encountered: