Dependency Array

Dependency array

Dependency arrays in React are used with many hooks, and all of them have essentially the same fundamental use which is to create memoization across renders to prevent excessive rendering or limit expensive computation.

All a dependency array is, is an array that contains all the variables that you make use of in your function that have been passed into the hook.

After an initial render the hook will not be re-run until the values in the dependency array change.

© 2024 MWXYZ