| 127 | } |
| 128 | |
| 129 | function 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 | |
| 171 | function createHook(): Hook { |
| 172 | if (numberOfReRenders > 0) { |