@sjblurton/use-axios-post
v0.1.2
Published
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.
Downloads
5
Maintainers
Readme
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