0.1.2 • Published 2 years ago

@sjblurton/use-axios-post v0.1.2

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

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

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago