UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

46 lines (36 loc) 1.13 kB
import { useRef, useEffect } from "react"; /** * This hook returns a previous value that was passed to it. * Eg. If on first render, you pass a "1" and on second render "2" the hook will return "1" * Hook is meant to mimic prevProps/prevState values that would be passed to the ComponenDidupdate function. * @param {*} value * @return {*} */ export const usePrevious = (value: any): any => { const ref = useRef(); useEffect(() => { ref.current = value; }); return ref.current; }; /** * Returns true if component is on the initial render * @return boolean */ export const useIsInitialRender = (): boolean => { const isInitialRenderRef = useRef(true); useEffect(() => { isInitialRenderRef.current = false; }, []); return isInitialRenderRef.current; }; export const checkIsLocalFeed = (feedUrl) => feedUrl?.startsWith("pipesv2://"); export const shouldDispatchData = ( url: string, feed: ZappPipesData | null, clearCache: boolean ) => { const currentFeedHasData = feed?.data; const isLocalFeed = checkIsLocalFeed(url); return !currentFeedHasData || clearCache || isLocalFeed; };