diff --git a/README.md b/README.md index a7dcc53056..757632da29 100644 --- a/README.md +++ b/README.md @@ -590,7 +590,7 @@ function Todos() { latestData, error, isFetching, - } = usePaginatedQuery(['todos', page], fetchProjects) + } = usePaginatedQuery(['projects', page], fetchProjects) return (
diff --git a/examples/pagination/pages/index.js b/examples/pagination/pages/index.js index 130accd60e..77e97f56f7 100755 --- a/examples/pagination/pages/index.js +++ b/examples/pagination/pages/index.js @@ -1,15 +1,15 @@ -import React from 'react' -import fetch from '../libs/fetch' - -import { usePaginatedQuery } from 'react-query' - -export default () => { +function Todos() { const [page, setPage] = React.useState(0) - const { status, resolvedData, data, error, isFetching } = usePaginatedQuery( - ['projects', page], - (key, page = 0) => fetch('/api/projects?page=' + page) - ) + const fetchProjects = (key, page = 0) => fetch('/api/projects?page=' + page) + + const { + status, + resolvedData, + latestData, + error, + isFetching, + } = usePaginatedQuery(['projects', page], fetchProjects) return (
@@ -18,24 +18,15 @@ export default () => { ) : status === 'error' ? (
Error: {error.message}
) : ( - // The data from the last successful page will remain - // available while loading other pages + // `resolvedData` will either resolve to the latest page's data + // or if fetching a new page, the last successful page's data
{resolvedData.projects.map(project => ( -

- {project.name} -

+

{project.name}

))}
)} - Current Page: {page + 1}{' '} + Current Page: {page + 1} {' '} - {// Since the data stick around between page requests, + {// Since the last page's data potentially sticks around between page requests, // we can use `isFetching` to show a background loading // indicator since our `status === 'loading'` state won't be triggered isFetching ? Loading... : null}{' '}