Skip to content

sjblurton/use-axios-post

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

custom React hook useAxiosPost with error handling and current status.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published