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.
npm i @sjblurton/use-axios-post
yarn add @sjblurton/use-axios-post
import useAxiosPost from "@sjblurton/use-axios-post";
const [status, setPost, error, response] = useAxiosPost<RequestData, ServerResponseData>();
returns a string of 'idle', 'pending', 'error', or 'success'
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",
},
})
returns an AxiosError response or undefined if no error
returns an AxiosResponse or undefined if not responded.
GitHub: https://github.com/sjblurton/use-axios-post
NPM: https://www.npmjs.com/package/@sjblurton/use-axios-post