Dependency arrays
In Kaioken, the dependency array is a crucial part of the useAsync, useCallback, useEffect, and useMemo hooks. It allows you to specify dependencies that the hook should watch for changes. When any of the dependencies change, the hook will re-run its logic.
Here's a breakdown of how to use the dependency array and its significance:
Specifying Dependencies: The dependency array is an argument provided to hooks like useCallback, useEffect, and useMemo. It's an array containing values (typically variables or state) that the hook relies on.
Monitoring Changes: When you provide a dependency array, Kaioken will compare the current values of the dependencies with their previous values on every render. If any of the dependencies have changed since the last render, the hook will be re-executed.
Empty Dependency Array: Providing an empty dependency array (
[]
) indicates that the hook should only run once, during the initial render. It's useful for scenarios where you want to perform an action only once or where the hook's logic doesn't depend on any external values.