Improve Blog Page
Fetch the next page data by React Query
I achieved using less code to fetch the next page using React Query. The key thing is that needs to create a function and put the fetch function inside to pass params. If without adding a function, it would fetch the same page.
const [fetchPage, setFetchPage] = useState(0)
const { data, error, status } = useQuery(["posts", fetchPage],
() => fetchData(fetchPage),
{ keepPreviousData: true })
const loadMoreButtonHandler = () => {
setFetchPage((page) => ++page)
}