MCPcopy
hub / github.com/preactjs/preact / updateHookState

Function updateHookState

hooks/src/index.js:237–261  ·  view source on GitHub ↗
(p, s, c)

Source from the content-addressed store, hash-verified

235 // @ts-ignore - We don't use TS to downtranspile
236 // eslint-disable-next-line no-inner-declarations
237 function updateHookState(p, s, c) {
238 if (!hookState._component.__hooks) return true;
239
240 // We check whether we have components with a nextValue set that
241 // have values that aren't equal to one another this pushes
242 // us to update further down the tree
243 let updatedHook = false;
244 let shouldUpdate = hookState._component.props !== p;
245 hookState._component.__hooks._list.some(hookItem => {
246 if (hookItem._nextValue) {
247 updatedHook = true;
248 const currentValue = hookItem._value[0];
249 hookItem._value = hookItem._nextValue;
250 hookItem._nextValue = undefined;
251 if (currentValue !== hookItem._value[0]) shouldUpdate = true;
252 }
253 });
254
255 if (prevScu) {
256 const result = prevScu.call(this, p, s, c);
257 return updatedHook ? result || shouldUpdate : result;
258 }
259
260 return !updatedHook || shouldUpdate;
261 }
262
263 currentComponent.shouldComponentUpdate = updateHookState;
264 }

Callers 1

useReducerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…