Creating effects
An effect can be skipped. As a matter of fact, an effect needs to be created in an update for it to take effect. This behavior is captured by a dependency array called deps
. React uses a utility function called areDepsEqual
to help decide whetherthis array changes. Let's take a closer look at this function:
function areDepsEqual(deps, prevDeps) { if (!prevDeps) { return false } for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) { if (Object.is(deps[i], prevDeps[i])) { continue } return false } return true }
The areDepsEqual
function is used to compare two dependency arrays between the previous prevDeps
array and the current deps
array and returns...