Releases: ilyalesik/react-fetch-hook
Releases · ilyalesik/react-fetch-hook
Improving useFetch error
Has implemented the ability to get error status code:
...
const Component = () => {
const { isLoading, data, error } = useFetch("https://swapi.co/api/people/1");
if (error) {
return <div>
<p>Code: ${error.status}</p>
<p>Message: ${error.statusText}</p>
</div>
}
...
};
isLoading=true by default
v1.7.0 Make isLoading true by default #13
v1.6.4
Add TypeScript typings
TypeScript typings is now included to package.
Add `usePaginatedRequest`
usePaginatedRequest
Create a paginated request.
usePaginatedRequest = <T>(
request: (params: { limit: number, offset: number }) => Promise<Array<T>>,
limit: number
): {
data: Array<T>,
loadMore?: () => mixed,
hasMore: boolean
};
Implement prevent call fetch
Implement prevent call fetch
For prevent call fetch you can pass preventCallFetch prop:
const {authToken} = useContext(authTokenContext);
const { isLoading, data } = useFetch("https://swapi.co/api/people/1", {
preventCallFetch: !authToken //don't call request, if haven't authToken
});