@vinsjo/use-axios
v1.0.8
Published
A react hook for making HTTP requests with Axios
Downloads
4
Readme
@vinsjo/use-axios
@vinsjo/use-axios
is a react hook for making HTTP requests with Axios
Package is bundled using microbundle
Installation
npm i @vinsjo/use-axios
Usage
const { data, loading, error } = useAxios({
url: 'http://example.com/api',
});
With TypeScript
const { data, loading, error } = useAxios<{ message: string }>({
url: 'http://example.com/api',
});
Example
import useAxios from '@vinsjo/use-axios';
const Example = () => {
const { data, loading, error } = useAxios<{ message: string }>({
url: 'http://example.com/api',
});
return (
<>
{data
? data.message
: error
? error.message
: loading
? 'Loading...'
: null}
</>
);
};