UNPKG

react-native-switch-month-week

Version:

react native calendar with a week and month view

36 lines (33 loc) 957 B
import React, { useEffect, useRef } from 'react'; /** * This hook avoid calling useEffect on the initial value of his dependency array */ export const useDidUpdate = (callback: () => void, dep: React.DependencyList) => { const isMounted = useRef(false); useEffect(() => { if (isMounted.current) { callback(); } else { isMounted.current = true; } }, dep); }; export const useCombinedRefs = (...refs: React.Ref<any>[]): React.MutableRefObject<undefined> => { const targetRef = React.useRef(); React.useEffect(() => { refs.forEach(ref => { if (!ref) { return; } if (typeof ref === 'function') { ref(targetRef.current); } else { // @ts-expect-error ref.current = targetRef.current; } }); }, [refs]); return targetRef; };