You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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])
This discussion was converted from issue #582 on June 29, 2024 12:15.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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])
};
Beta Was this translation helpful? Give feedback.
All reactions