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-storex

v1.0.11

Published

Custom React / React Native store solution with hooks, caching, pagination, and JWT integration

Readme

react-storex

This library provides a simple global state management solution with API integration, caching, and a custom React hook called useStore.It allows you to easily fetch, update, delete, and edit data while keeping your components in sync with a centralized store.

Features

  • 🚀 Global state management with React hook interface
  • 🔄 Automatic API synchronization with retry logic
  • ⚡ Optimistic UI updates for mutations
  • 🗄️ Intelligent caching with TTL support
  • 🔄 Exponential backoff for failed requests
  • ✨ Built-in CRUD operations for common data patterns

Installation

npm install react-storex

Create a Store Instance

  • Before using the hook, initialize the store in your application with an initial state.
import { createStore } from "react-storex";

const initialState = {
  users: [],
  products: [],
};

export const store = createStore(initialState);

Register API endpoints

  • Register an API handler for a specific key in your store. This handler defines how data is fetched and sets a cache duration (in milliseconds):
import { registerAPI } from "react-storex";

registerAPI(
  "items",
  async () => {
    const response = await fetch("/api/items");
    const data = await response.json();
    return data;
  },
  60000
);
// Cache duration: 60 seconds (optional) default is 60 seconds

// if you want to register multiple endpoints, you can do it like this:

const apiConfig = {
  products: (urlPath = "") => apiClient(`products${urlPath}`),

  addProduct: (productData) => apiClient("products", "POST", productData),
};

Object.entries(apiConfig).forEach(([key, handler]) => {
  registerAPI(key, handler, 60000);
});

Use the useStore Hook in Your Component

  • Use the custom hook to connect your component to the store. This hook supports fetching, mutations, deleting, and editing data.
import React from "react";
import { useStore } from "react-storex";

const ItemsList = () => {
  const {
    state,
    isLoading,
    isError,
    executeMutation,
    deleteItem,
    editItem,
    refreshData,
  } = useStore({
    key: "items", // the key of the item in the store (required)
    method: "GET", // the method to use for the request (optional) e.g. 'GET', 'POST', 'PUT', 'DELETE'
    payload: null, // the payload to send with the request (optional) e.g. { name: 'John' }
    itemId: null, // the id of the item if you want to get specific items from array (optional) e.g. 1
    urlPath: "", // the path to the url (optional) e.g. /items/1
    keepCache: false, // whether to keep the cache of the item (optional) e.g. true, false
    idKey: id, // Identifier key in your data objects, we need this to edit and delete the items (required)
  });

  if (isLoading) return <div>Loading...</div>;
  if (isError) return <div>Error loading items.</div>;

  const forceRefetch = () => {
    refreshData();
  };

  return (
    <div>
      {state.map((item) => (
        <div key={item.id}>
          <span>{item.name}</span>
          <button onClick={() => deleteItem(item.id)}>Delete</button>
          <button onClick={() => editItem(item.id, { name: "Updated Name" })}>
            Edit
          </button>
        </div>
      ))}

      <button onClick={() => forceRefetch()}>Force Refetch Data</button>
    </div>
  );
};

export default ItemsList;

Triggering Mutations in Your Component

  • Example usage of executeMutation for POST or PUT requests
const { executeMutation } = useStore({ key: "items", method: "PUT" });
executeMutation({ id: 1, name: "New Item Name" });

Local Data Manipulation

  • Example usage of deleteItem and editItem
// **Delete an Item Locally from the Store**
deleteItem(itemId);

// **Edit an Item Locally in the Store**
editItem(itemId, { name: "Updated Name" });

Clear Cache

import { clearCache } from "react-storex";

// **Clear Cache for a Specific Key**
clearCache(key);

// **Clear All Cache**
clearCache();

Understanding Local Mutations

The library provides utility functions to modify the store's data locally:

  • executeMutation: For performing POST or PUT operations. This function handles the API call, applies optimistic updates, and manages error handling.
  • deleteItem: Removes an item from the store state by its ID, this will not make api call to the server insted it will delete the item from local store.
  • editItem: Updates an item in the store state locally by merging updated fields, this will not make api call to the server insted it will edit the item from local store.

Retry Mechanism & Caching

  • Retry Fetch: The retryFetch function automatically retries API calls with exponential backoff in case of errors.
  • Caching: Data fetched from the API is cached for the duration specified during API registration. You can also manually clear the cache using the clearCache method on the store.

License

MIT