1.0.3 • Published 1 month ago

react-generic-api-call-hooks v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

React Generic API Call Custom Hook

This custom hook allows you to make generic API calls in your React application with ease. The hook abstracts the common logic for making API requests, so you can focus on building your application's unique features.

For a detailed explanation on how to use this custom hook, check out the article on Medium: React Generic API Calls with Custom Hooks

Usage

To use this custom hook, simply import it into your React component and pass in the necessary parameters for your API call (e.g., URL, request method, request body, etc.). The hook will return the response data, loading state, and any errors that may have occurred during the request.

Example

Here's a basic example of how to use the custom hook in a component:

import React from "react";
import {useGet} from "react-generic-api-call-hooks";

const MyComponent = () => {
 	const {getData, data , isLoading, error} = useGet()

  useEffect(()=>{
    getData('url','token)
  },[])

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      <h1>Data from API:</h1>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
};

export default MyComponent;
1.0.3

1 month ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago