UNPKG

react-native-tree-multi-select

Version:

A super-fast, customizable tree view component for React Native with multi-selection, checkboxes, and search filtering capabilities.

36 lines (31 loc) 1.23 kB
"use strict"; import React 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 track if it's the first render const firstRenderRef = React.useRef(true); // Memoized dependencies to avoid redundant `isEqual` checks const memoizedDependencies = React.useMemo(() => deps, [deps]); // Ref to store the previous dependencies const dependenciesRef = React.useRef(memoizedDependencies); // Check for dependency changes const dependenciesChanged = !fastIsEqual(dependenciesRef.current, memoizedDependencies); if (dependenciesChanged) { dependenciesRef.current = memoizedDependencies; } React.useEffect(() => { if (firstRenderRef.current) { firstRenderRef.current = false; } return effect(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [dependenciesChanged]); // exclude the effect function from the dependencies } //# sourceMappingURL=useDeepCompareEffect.js.map