1.0.2 • Published 2 years ago

use-api-call-hook v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

use-api-call

Custom hook for making API calls with loading state.

Installation

You can install the package via npm:

npm install use-api-call
yarn add use-api-call

Examples

import React from 'react';
import useApiCall from 'use-api-call';

const YourComponent = () => {
  const { loading, error, data, makeApiCall } = useApiCall(yourApiFunction);

  const handleButtonClick = () => {
    makeApiCall(/* your API request parameters */);
  };

  return (
    <div>
      <button onClick={handleButtonClick} disabled={loading}>
        {loading ? 'Loading...' : 'Make API Call'}
      </button>
      {error && <div>Error: {error.message}</div>}
      {data && <div>Data: {JSON.stringify(data)}</div>}
    </div>
  );
};

export default YourComponent;
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago