react-use-request
Experimental React hook for making HTTP Requests with axios.
{ const loading data error = if loading return <Spinner /> if error return <Error error=error /> return <ul> data </ul> }
features
- Support the same options as axios does
- Request cancellation out-of-box (no request duplication, no worry about unmounts)
installation
You need to install axios too:
yarn add react-use-request axios
npm install react-use-request axios --save
usage
It supports all options as axios does. But it supports three additional options:
lazy: Boolean
const request =
onSuccess: function (response)
onErrror: function (err)
factory
You may want to use a custom instance of axios. To do so, just use the factory function:
const customAxios = axios const useRequest =
Then, just use useRequest
as a normal hook.
license
MIT