Skip to content

Commit

Permalink
docs: Add paginated() to readme (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker authored Jun 2, 2021
1 parent f8f2bef commit 44b85ed
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,41 @@ const createUser = new Endpoint(postToUserFunction, {
- Faster
- Entity has no defined key lookups - but EntityRecord does.
- BaseResource is missing predefined endpoints (list, detail, etc), but has everything else
### Resource.list() declarative pagination
Addition of `paginated()`.
```ts
class NewsResource extends Resource {
static listPage<T extends typeof NewsResource>(this: T) {
return this.list().paginated(({ cursor, ...rest }) => [rest]);
}
}

```
```tsx
import { useResource } from 'rest-hooks';
import NewsResource from 'resources/NewsResource';

function NewsList() {
const { results, cursor } = useResource(NewsResource.list(), {});
const curRef = useRef(cursor);
curRef.current = cursor;
const fetch = useFetcher();
const getNextPage = useCallback(
() => fetch(NewsResource.listPage(), { cursor: curRef.current }),
[]
);

return (
<Pagination onPaginate={getNextPage} nextCursor={cursor}>
<NewsList data={results} />
</Pagination>
);
}
```

0 comments on commit 44b85ed

Please sign in to comment.