@sjblurton/use-axios-post
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

useAxiosPost

useAxiosPost a React custom hook fully tested that returns a tuple of status, a function to make a post request, and axios error response, and the success response.

install

npm i @sjblurton/use-axios-post

yarn add @sjblurton/use-axios-post

Import useAxiosPost

import useAxiosPost from "@sjblurton/use-axios-post";

To call the hook...

const [status, setPost, error, response] = useAxiosPost<RequestData, ServerResponseData>();

status

returns a string of 'idle', 'pending', 'error', or 'success'

setPost

takes one object with two values, the url and a string, and the JSON body of the post.

setPost({
            url: "https://reqreres.in/api/",
            post: {
              name: "morpheus",
              job: "leader",
            },
          })

error

returns an AxiosError response or undefined if no error

response

returns an AxiosResponse or undefined if not responded.

Links

GitHub: https://github.com/sjblurton/use-axios-post
NPM: https://www.npmjs.com/package/@sjblurton/use-axios-post

Package Sidebar

Install

npm i @sjblurton/use-axios-post

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

204 kB

Total Files

23

Last publish

Collaborators

  • sjblurton