MCPcopy
hub / github.com/facebook/react / areHookInputsEqual

Function areHookInputsEqual

packages/react-server/src/ReactFizzHooks.js:129–169  ·  view source on GitHub ↗
(
  nextDeps: Array<mixed>,
  prevDeps: Array<mixed> | null,
)

Source from the content-addressed store, hash-verified

127}
128
129function areHookInputsEqual(
130 nextDeps: Array<mixed>,
131 prevDeps: Array<mixed> | null,
132) {
133 if (prevDeps === null) {
134 if (__DEV__) {
135 console.error(
136 '%s received a final argument during this render, but not during ' +
137 'the previous render. Even though the final argument is optional, ' +
138 'its type cannot change between renders.',
139 currentHookNameInDev,
140 );
141 }
142 return false;
143 }
144
145 if (__DEV__) {
146 // Don't bother comparing lengths in prod because these arrays should be
147 // passed inline.
148 if (nextDeps.length !== prevDeps.length) {
149 console.error(
150 'The final argument passed to %s changed size between renders. The ' +
151 'order and size of this array must remain constant.\n\n' +
152 'Previous: %s\n' +
153 'Incoming: %s',
154 currentHookNameInDev,
155 `[${nextDeps.join(', ')}]`,
156 `[${prevDeps.join(', ')}]`,
157 );
158 }
159 }
160 // $FlowFixMe[incompatible-use] found when upgrading Flow
161 for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
162 // $FlowFixMe[incompatible-use] found when upgrading Flow
163 if (is(nextDeps[i], prevDeps[i])) {
164 continue;
165 }
166 return false;
167 }
168 return true;
169}
170
171function createHook(): Hook {
172 if (numberOfReRenders > 0) {

Callers 3

useMemoFunction · 0.85
ifFunction · 0.85
ReactFiberHooks.jsFile · 0.85

Calls 3

isFunction · 0.85
joinMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected