UNPKG

react-native-tree-multi-select

Version:

Super-fast, customizable tree view component for React Native with drag-and-drop reordering, multi-selection, and search filtering.

29 lines (26 loc) 1.01 kB
"use strict"; import { useEffect, useRef } from "react"; import { fastIsEqual } from "fast-is-equal"; /** * Deep compare effect hook. * Ensures the effect runs on the first render and whenever dependencies deeply change. * * @param effect The effect callback function. * @param deps The dependencies array to compare deeply. */ export default function useDeepCompareEffect(effect, deps) { // Ref to store the previous dependencies const dependenciesRef = useRef(deps); // Monotonic change counter: a boolean flag would stay `true` across two // consecutive deep changes and useEffect would miss the second one. const changeSignalRef = useRef(0); if (!fastIsEqual(dependenciesRef.current, deps)) { dependenciesRef.current = deps; changeSignalRef.current += 1; } useEffect(() => effect(), // eslint-disable-next-line react-hooks/exhaustive-deps [changeSignalRef.current] // exclude the effect function from the dependencies ); } //# sourceMappingURL=useDeepCompareEffect.js.map