const dispatch = useDispatch();
useEffect(()=>{
//get the user post
dispatch(setStorageKey('homeposts'))
}, [])
useEffect(()=>{
if (!loadingUpdates )
{
console.log(upDates)
if (upDates){
if (upDates.data > 0){
mutate([...postdata.data, upDates.data]
, false);
}
}
}
}, [upDates, loadingUpdates])
console.log(upDates)
useEffect(()=>{
//get the user post
dispatch(setStorageKey('homeposts'))
}, [persistData])
Please i want to update the data in the intial requested swr with the data of the second updated swr request export default
function Home({data}){ const [page, setPage] = useState(1) const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const [persistData, setPersistData ] = useRemember([], 'homeposts'); const [shouldFetch, setShouldFetch] = useState(true);
const {ref, inView} = useInView({ threshold: 0, })
const {cursors, setCursors, updateNextCursors, refresh} = usePaginate();
const [nextCursors, setNextCursors] = useState(cursorData); const getQueryString = () => { let queryString =
/home?page=${page}
; const cursorString = encodeURIComponent(cursors.post_id);}; const initialQueryString =
/home?page=${page}
; const {data: homeespo, isLoading: homeloading, isError: homeerror, mutate} = useSWR(initialQueryString, fetcher) const {data: upDates, isLoading: loadingUpdates} = useSWR(cursors?.state ? getQueryString() :null, fetcher);const dispatch = useDispatch(); useEffect(()=>{ //get the user post dispatch(setStorageKey('homeposts')) }, []) useEffect(()=>{ if (!loadingUpdates ) { console.log(upDates) if (upDates){ if (upDates.data > 0){ mutate([...postdata.data, upDates.data] , false); } } } }, [upDates, loadingUpdates]) console.log(upDates) useEffect(()=>{ //get the user post dispatch(setStorageKey('homeposts')) }, [persistData])
const handleRefresh = () => { setLoading(true); setPage(1); setNextCursors(cursorData); setShouldFetch(true); };
if (!homeloading){ console.log(homeerror) if (homeespo){
} // Function to load more posts
useEffect(()=>{ if (inView){ updateNextCursors(homeespo.data); console.log('loading')
}
}, [inView])
};