0.0.5 • Published 2 years ago

react-hooks-box v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-hooks-box

NPM npm

The useAxios hook for React that automatically handles the request cancellation on unmount, triggers the call after your component mount or manually, etc.

Install

npm install --save react-hooks-box

Or with yarn:

yarn add react-hooks-box

How to use useAxios custom hook

import useAxios from 'react-hooks-box/useAxios';

then inside your functional component:

const [{ isLoading, response, error }, request] = useAxios({
     method: 'get',
     url: 'my-url',
     afterMount: true,
     axiosConfig
   });

Inputs:

  • afterMount {boolean}: set to true will execute the axios call just after the mount. It's false by default.
  • axiosConfig {Object}: all classic axios config object.

    Outputs

  • request {Function}: a function that will trigger axios call manually with extended axios config object (optional) as parameter.

  • isLoading {boolean}: a flag set to true when the axios call is in process, by default 'false'.
  • response {Object}: an object that contains the data response if the axios call is successful, by default 'undefined'.
  • error {Object}: an object that contains the error object if the axios call has failed, by default 'undefined'.

License

MIT

0.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago