Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #62- Add useFetch Custom hook #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rray524
Copy link
Collaborator

@rray524 rray524 commented Dec 24, 2024

Checklist:

  • Added useFetch custom hook

Resolves #62

How to use this useFetch hook?

Usage Example of Theme Toggling:

import useFetch from './useFetch';

const MyComponent = () => {
  const { data, error, loading, refetch } = useFetch('https://api.example.com/data', { method: 'GET' });

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

  return (
    <div>
      <h1>Data</h1>
      <pre>{JSON.stringify(data, null, 2)}</pre>
      <button onClick={refetch}>Refetch</button>
    </div>
  );
};

export default MyComponent;

Description

The useFetch hook is a reusable custom React hook for making API requests. It supports various HTTP methods like GET, POST, PUT, DELETE, and PATCH, while managing loading, error, and data states. With built-in flexibility for auto-fetching and a refetch method, it simplifies API interactions for components. Developers can use it to streamline data fetching and improve code readability.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Create custom useFetch hook
2 participants