Skip to content

Commit ab0a86c

Browse files
committed
refactor(use-uncontrolled): remove inline reducer memoization
1 parent 97c4fa0 commit ab0a86c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/use-uncontrolled/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ export function useUncontrolled<T, E extends HTMLInputElement | HTMLSelectElemen
1212

1313
// Although the `transformValue` is most likely not stable, still wraps it with `useCallback` in case the
1414
// user does memoize it and we are able to opt-in useReducer's internal optimization.
15-
const reducer = useCallback((_prevState: T, valueAsAction: T) => {
15+
//
16+
// **UPDATE**
17+
// React removes the eager reducer bailout since React 18, so memoize the reducer is no longer necessary.
18+
// https://github.com/facebook/react/pull/22445
19+
const reducer = (_prevState: T, valueAsAction: T) => {
1620
return transformValue(valueAsAction);
17-
}, [transformValue]);
21+
};
1822

1923
const [uncontrolledValue, setUncontrolledValue] = useReducer(reducer, initialValue);
2024

0 commit comments

Comments
 (0)