Skip to content

Commit f23272c

Browse files
authored
Golf down hooks impl (#4897)
1 parent 025875a commit f23272c

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

hooks/src/index.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,15 @@ export function useReducer(reducer, initialState, init) {
240240
function updateHookState(p, s, c) {
241241
if (!hookState._component.__hooks) return true;
242242

243-
/** @type {(x: import('./internal').HookState) => x is import('./internal').ReducerHookState} */
244-
const isStateHook = x => !!x._component;
245-
const stateHooks =
246-
hookState._component.__hooks._list.filter(isStateHook);
247-
248-
const allHooksEmpty = stateHooks.every(x => !x._nextValue);
249-
// When we have no updated hooks in the component we invoke the previous SCU or
250-
// traverse the VDOM tree further.
251-
if (allHooksEmpty) {
252-
return prevScu ? prevScu.call(this, p, s, c) : true;
253-
}
243+
const hooksList = hookState._component.__hooks._list;
254244

255245
// We check whether we have components with a nextValue set that
256246
// have values that aren't equal to one another this pushes
257247
// us to update further down the tree
258-
let shouldUpdate = hookState._component.props !== p;
259-
stateHooks.forEach(hookItem => {
248+
let shouldUpdate =
249+
hookState._component.props !== p ||
250+
hooksList.every(x => !x._nextValue);
251+
hooksList.forEach(hookItem => {
260252
if (hookItem._nextValue) {
261253
const currentValue = hookItem._value[0];
262254
hookItem._value = hookItem._nextValue;
@@ -275,7 +267,7 @@ export function useReducer(reducer, initialState, init) {
275267
}
276268
}
277269

278-
return hookState._nextValue || hookState._value;
270+
return hookState._value;
279271
}
280272

281273
/**

0 commit comments

Comments
 (0)