Skip to content

Instantly share code, notes, and snippets.

@ChaseH88
Last active April 11, 2021 19:07
Show Gist options
  • Select an option

  • Save ChaseH88/cb6897a205e5667b8fe3bb8b4febd6af to your computer and use it in GitHub Desktop.

Select an option

Save ChaseH88/cb6897a205e5667b8fe3bb8b4febd6af to your computer and use it in GitHub Desktop.
import axios from 'axios';
/**
* This hook makes use of the axios dependency.
* @param path the endpoint in which you wish to make a request to
* @param method the request method.. can be either 'get' or 'post'.
* @param data an object containing the data/payload
* @returns
*/
const useAxios = async (
path: string,
method: 'get' | 'post' = 'get',
data: { [key: string]: any } = {}
) => (
await axios[method](path, data)
);
export { useAxios };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment