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

xanreso

v1.0.2

Published

A lightweight hook-first React library for async data fetching with automatic updates, caching, and polling support.

Downloads

204

Readme

Perfect! I’ve drafted a beautiful, professional documentation for your final xanreso version. It covers everything: installation, usage, options, and examples.


xanreso — React Hook-First Async Resource Library

A tiny, hook-first library to manage async data fetching in React with automatic re-renders, caching per arguments, polling, and reload support.


Installation

npm install xanreso
# or
yarn add xanreso

API

createResource(fetcher, options?)

Creates a React hook for your async resource.

Parameters:

| Name | Type | Description | | --------- | ------------------------- | ------------------------------------------------------------------- | | fetcher | (args: A) => Promise<T> | Async function that fetches your data. Receives optional arguments. | | options | ResourceOptions | Optional configuration object. |

ResourceOptions:

| Option | Type | Default | Description | | ------------ | --------- | ----------- | --------------------------------------------------------------- | | intialLoad | boolean | true | Whether to automatically load data when the hook is first used. | | interval | number | undefined | Polling interval in milliseconds to automatically reload data. |

Returns:

A React hook: (args?: A) => ResourceHookResult<T>


ResourceHookResult

| Property | Type | Description | | ----------- | --------------------- | ---------------------------------------- | | data | T \| null | Fetched data for the given arguments. | | error | unknown | Error object if fetch fails. | | isLoading | boolean | true while data is loading. | | isSuccess | boolean | true if loading finished successfully. | | isError | boolean | true if there was an error. | | reload() | () => Promise<void> | Reloads the resource manually. |


Basic Usage

import { createResource } from "xanreso";

// Create the hook
export const useUserResource = createResource(
  async () => {
    const res = await fetch("https://randomuser.me/api/");
    return (await res.json()).results[0];
  }
);

// Component
function Profile() {
  const user = useUserResource();

  if (user.isLoading) return <p>Loading...</p>;
  if (!user.data) return <p>No user data</p>;

  return (
    <div>
      <img src={user.data.picture.large} />
      <h2>{user.data.name.first} {user.data.name.last}</h2>
      <button onClick={user.reload}>Reload</button>
    </div>
  );
}

Using Arguments

// Hook with args
export const useUsersResource = createResource(
  async ({ results, gender }: { results?: number; gender?: string }) => {
    const url = new URL("https://randomuser.me/api/");
    if (results) url.searchParams.set("results", String(results));
    if (gender) url.searchParams.set("gender", gender);
    const res = await fetch(url.toString());
    return (await res.json()).results;
  }
);

// Component
function UsersList() {
  const users = useUsersResource({ results: 5, gender: "female" });

  if (users.isLoading) return <p>Loading...</p>;

  return (
    <ul>
      {users.data?.map((u, i) => (
        <li key={i}>{u.name.first} {u.name.last}</li>
      ))}
    </ul>
  );
}

Polling / Auto Reload

export const useLiveUsers = createResource(
  async () => {
    const res = await fetch("https://randomuser.me/api/");
    return (await res.json()).results[0];
  },
  { interval: 5000 } // reload every 5 seconds
);

function LiveProfile() {
  const user = useLiveUsers();

  return (
    <div>
      {user.isLoading ? "Loading..." : user.data?.name.first}
      <button onClick={user.reload}>Reload Now</button>
    </div>
  );
}

Features

  • ✅ Hook-first API — easy to use in components
  • ✅ Shared state per argument combination
  • ✅ Auto re-render of all components using the hook
  • ✅ Polling support with interval
  • ✅ Manual reload with reload()
  • ✅ Simple argument-based caching
  • ✅ Tiny and dependency-free

Best Practices

  • Always call your hook at the top level of the component.
  • For multiple datasets, call the hook with different argument objects.
  • Do not call React hooks inside the fetcher — pass hook values as arguments instead.