UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

43 lines (39 loc) 1.33 kB
import React from "react"; import { useDispatch } from "react-redux"; import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation"; import { getDatasourceUrl, usePipesContexts, } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils"; import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes"; /** * reset river components cache when screen is unmounted * @param {string} riverId screen id * @param {Array} riverComponents list of UI components */ export const usePipesCacheReset = (riverId, riverComponents) => { const dispatch = useDispatch(); const { screenData, pathname } = useRoute(); const pipesContexts = usePipesContexts(riverId, pathname); React.useEffect(() => { return () => { riverComponents.forEach((component) => { if ( component?.rules?.clear_cache_on_reload && component?.data?.source && // We don't want to refresh cache when closing/minimising videoModal !pathname.includes("videoModal") ) { const url = getDatasourceUrl( { screenData, ...pipesContexts, }, component ); dispatch(clearPipesData(url, { riverId })); } }); }; }, []); };