npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-fetch-pilot

v1.0.1

Published

A flexible React data-fetching custom hook

Readme

react-fetch-pilot

A lightweight, feature-rich React hooks library for API data fetching and mutations with built-in retry logic, polling, and window focus refetching.

Features

  • 🚀 Simple API - Intuitive hooks for queries and mutations
  • 🔄 Auto Retry - Built-in exponential backoff retry logic
  • Polling - Configurable refetch intervals
  • 🎯 Window Focus Refetch - Automatically refetch when tab regains focus
  • 🛡️ Abort Support - Automatic request cancellation on unmount
  • 📦 Zero Dependencies - Only requires React 16.8+
  • 🎣 TypeScript Ready - Full type support out of the box

Installation

npm install react-fetch-pilot
# or
yarn add react-fetch-pilot

useDataFetcher (For GET/Queries)

import { useDataFetcher } from 'react-fetch-pilot';

function UserList() {
  const { data, error, loading, refetch } = useDataFetcher(
    [], // dependencies array
    async (signal) => {
      const response = await fetch('/api/users', { signal });
      const data = await response.json();
      return { data };
    },
    {
      enabled: true,
      refetchInterval: 5000,
      refetchOnWindowFocus: true,
      retry: 3,
      retryDelay: 1000,
      onSuccess: (data) => console.log('Success:', data),
      onError: (error) => console.error('Error:', error)
    }
  );

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

  return (
    <div>
      {data?.map(user => <div key={user.id}>{user.name}</div>)}
      <button onClick={refetch}>Refresh</button>
    </div>
  );
}

useMutation (For POST/PUT/DELETE)

import { useMutation } from 'react-fetch-pilot';

function CreateUser() {
  const { execute, data, error, loading } = useMutation(
    async (userData) => {
      const response = await fetch('/api/users', {
        method: 'POST',
        body: JSON.stringify(userData),
        headers: { 'Content-Type': 'application/json' }
      });
      const data = await response.json();
      return { data };
    },
    {
      onSuccess: (data) => console.log('User created:', data),
      onError: (error) => console.error('Failed:', error)
    }
  );

  const handleSubmit = async (e) => {
    e.preventDefault();
    try {
      const result = await execute({ name: 'John Doe', email: '[email protected]' });
      console.log('Created user:', result);
    } catch (error) {
      console.error('Submission failed:', error);
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      <button type="submit" disabled={loading}>
        {loading ? 'Creating...' : 'Create User'}
      </button>
    </form>
  );
}

API Reference

UseDataFetcher

useDataFetcher<TData, TError>(
  dependencies: DependencyList,
  apiFunction: (signal: AbortSignal) => Promise<{ data: TData }>,
  options?: UseDataFetcherOptions
): UseDataFetcherResult

Options

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Enable/disable automatic fetching | | refetchInterval | number | undefined | Polling interval in milliseconds | | refetchOnWindowFocus | boolean | false | Refetch when window regains focus | | retry | number | 0 | Number of retry attempts on failure | | retryDelay | number | 1000 | Base delay between retries (ms) | | onSuccess | (data) => void | - | Callback on successful fetch | | onError | (error) => void | - | Callback on fetch error |


useMutation


useMutation<TData, TArgs, TError>(
  apiFunction: (...args: TArgs) => Promise<{ data: TData }>,
  options?: UseMutationOptions
): UseMutationResult

Returns: { execute, data, error, loading }


Examples:

Basic Fetch with Dependencies:

const [userId, setUserId] = useState(1);

const { data, loading } = useDataFetcher(
  [userId],
  async (signal) => {
    const res = await fetch(`/api/users/${userId}`, { signal });
    return { data: await res.json() };
  }
);

Manual Execution Only:

const { data, loading, refetch } = useDataFetcher(
  [],
  fetchUsers,
  { enabled: false }
);

<button onClick={refetch}>Load Users</button>

Error Handling with Retry:

const { data, error, loading } = useDataFetcher(
  [],
  fetchCriticalData,
  {
    retry: 5,
    retryDelay: 2000,
    onError: (err) => {
      console.error('Failed after retries:', err);
    }
  }
);

TypeScript Support

The library is written in TypeScript and includes type definitions. You can use generics to type your data:

interface User {
  id: number;
  name: string;
  email: string;
}

const { data, error } = useDataFetcher<User>(
  [],
  async (signal) => {
    const res = await fetch('/api/user', { signal });
    return { data: await res.json() };
  }
);

Browser Support

  • Chrome 66+
  • Firefox 57+
  • Safari 12.1+
  • Edge 79+

📄 License

Universal Unit is released under the MIT License.

You are free to use, modify, distribute, and integrate the package into your projects according to the terms of the MIT License.