1.1.1 • Published 11 months ago

@asxasdfghjkl/react-use-api v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

react-use-api

An api hook for React.js with Axios

Getting Started

yarn add @asxasdfghjkl/react-use-api axios
or
npm install @asxasdfghjkl/react-use-api axios

Basic usage

import { useApi, LoadingState } from '@asxasdfghjkl/react-use-api';

const DataDisplay = () => {
  const [payload, loading, load] = useApi({
    url: 'https://jsonplaceholder.typicode.com/todos/{id}',
    initialValue: null,
  });

  React.useEffect(() => {
    load({
      params: { id: 1 },
      // query: { action: 'test' },
      // body: { data: 'hi' }
    });
  }, []);

  if (loading === LoadingState.Pending) {
    return <h1>Loading...</h1>;
  }

  return JSON.stringify(payload);
};
1.1.1

11 months ago

1.1.0

11 months ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago