@vinsjo/use-axios
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

@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}
        </>
    );
};

Readme

Keywords

Package Sidebar

Install

npm i @vinsjo/use-axios

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

26.4 kB

Total Files

7

Last publish

Collaborators

  • vinsjo