T
TanStack2y ago
fair-rose

queryclient

Not being able to fetch my chats properly using useInfiniteQuery
3 Replies
fair-rose
fair-roseOP2y ago
const dispatch = useDispatch();
const { chatusers, error, loading } = useSelector((state) => state.chat);

const fetchUsers = async ({ pageParam }) => {
dispatch(getMyChats(pageParam));
return chatusers?.users || [];
};

const { data, fetchNextPage, isFetchingNextPage, hasNextPage } = useInfiniteQuery({
queryKey: ['query'],
queryFn: fetchUsers,
initialPageParam: 1,
getNextPageParam: (_, pages) => {
return pages.length + 1;
},
});

const { ref, inView } = useInView();

useEffect(() => {
if (inView && hasNextPage) {
fetchNextPage();
}
}, [inView, hasNextPage, fetchNextPage]);
const dispatch = useDispatch();
const { chatusers, error, loading } = useSelector((state) => state.chat);

const fetchUsers = async ({ pageParam }) => {
dispatch(getMyChats(pageParam));
return chatusers?.users || [];
};

const { data, fetchNextPage, isFetchingNextPage, hasNextPage } = useInfiniteQuery({
queryKey: ['query'],
queryFn: fetchUsers,
initialPageParam: 1,
getNextPageParam: (_, pages) => {
return pages.length + 1;
},
});

const { ref, inView } = useInView();

useEffect(() => {
if (inView && hasNextPage) {
fetchNextPage();
}
}, [inView, hasNextPage, fetchNextPage]);
i can only see the first 2 users actually it is only working when i click on the fetchNextPage Button and not automatically
fair-rose
fair-roseOP2y ago
i have alot of other users, still
fair-rose
fair-roseOP2y ago
the page numbers are being sent in this order, which is not right.. 1 2 1 1 2 1 2 3 1 3 2 1

Did you find this page helpful?