Skip to content

Commit cf61016

Browse files
author
Alex Cory
committed
Merge branch 'master' of github.com:alex-cory/react-usefetch
2 parents 7775dcc + c9f1486 commit cf61016

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Features
7373
- Provider to set default `url` and `options`
7474
- Request/response interceptors <!--https://github.com/alex-cory/use-http#user-content-interceptors-->
7575
- React Native support
76+
- Aborts/Cancels pending http requests when a component unmounts
7677

7778
Usage
7879
-----
@@ -741,13 +742,37 @@ Todos
741742
retryOnError: false,
742743

743744
refreshWhenHidden: false,
745+
746+
// this will allow you to merge the data the way you would like
747+
paginate: (currData, newData) => {
748+
return [...currData, ...newData]
749+
},
744750
})
745751
```
746752
- resources
747753
- [retryOn/retryDelay (fetch-retry)](https://www.npmjs.com/package/fetch-retry#example-retry-on-503-service-unavailable)
748754
- [retryDelay (react-query)](https://github.com/tannerlinsley/react-query)
749755
- [zeit's swr](https://github.com/zeit/swr)
750-
756+
- [ ] potential syntax for pagination
757+
```js
758+
const App = () => {
759+
const [page, setPage] = useState(1)
760+
const { data, loading } = useFetch({
761+
onMount: true,
762+
onUpdate: [page],
763+
path: `/todos?page=${page}&pageSize=15`,
764+
paginate: (currData, newData) => [...currData, ...neweData],
765+
data: []
766+
})
767+
768+
return (
769+
<>
770+
{data.map(item => <div key={item.id}>{item.name}</div>}
771+
<button onClick={() => setPage(page + 1)}>Load More</button>
772+
</>
773+
)
774+
}
775+
```
751776
- [ ] potential option ideas for `GraphQL`
752777
```jsx
753778
const request = useQuery({ onMount: true })`your graphql query`

0 commit comments

Comments
 (0)