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-smart-crud

v0.2.0

Published

Minimal optimistic CRUD helper for React without useState, useEffect, or prop drilling

Downloads

1,137

Readme

react-smart-crud

A minimal, smart CRUD helper for React No Redux. No Zustand. No boilerplate.

Designed for API management systems.

✨ Features

  • 🧠 Global cache (shared across components)
  • ♻️ Automatic re-fetch & sync after mutations
  • 🔐 Optional auth token support
  • 🔔 Optional toast / notification support
  • 🧩 Zero external state library
  • ✨ Very small API surface

📦 Installation

npm create vite@latest my-project

cd my-project

npm install react-smart-crud

Optional dependency for notifications:

npm install react-hot-toast

⚙️ One-time Setup (Required)

Create a setup file once in your app.

📄 src/main.jsx

import { setupCrud } from "react-smart-crud";
import toast from "react-hot-toast";

setupCrud({
  baseUrl: "https://api.example.com/",
  getToken: () => localStorage.getItem("token"),
  notify: (type, message) => {
    if (type === "success") toast.success(message);
    if (type === "error") toast.error(message);
  },
});

⚠️ Do this only once in your app.


🧠 useCrud Hook

const { data, loading, error } = useCrud("users");

Returned values

| key | type | description | | ------- | ------- | ------------- | | data | array | cached data | | loading | boolean | request state | | error | any | error info |


✍️ Create (POST)

createItem("users", { name: "John" });

After creation, the library refetches the data automatically to keep your cache in sync.


🔄 Update (PUT)

updateItem("users", 1, { name: "Updated" });

After update, all subscribers automatically get the latest data.


❌ Delete (DELETE)

deleteItem("users", 1);

After deletion, cache and UI are automatically updated.


📂 Example Endpoints

| Action | Endpoint | | ------ | ----------------- | | Fetch | GET /users | | Create | POST /users | | Update | PUT /users/:id | | Delete | DELETE /users/:id |


🧪 Works With

  • REST APIs
  • Laravel / Express / Django
  • Admin dashboards
  • School / Business management systems
  • Small to mid projects

🧩 Philosophy

Simple cache + smart subscribers No unnecessary abstraction Let React re-render naturally


📄 License

MIT © Tarequl Islam


✅ REAL-WORLD EXAMPLE (Vite + React)

📄 UserPage.jsx

import { useCrud, createItem, deleteItem } from "react-smart-crud";

export default function UserPage() {
  const { data: users, loading, error } = useCrud("users");

  if (loading) return <p>Loading...</p>;
  if (error) return <p>Something went wrong</p>;

  return (
    <div style={{ padding: 20 }}>
      <h2>Users</h2>

      <button
        onClick={() =>
          createItem("users", {
            name: "New User",
            email: "[email protected]",
          })
        }
      >
        ➕ Add User
      </button>

      <ul>
        {users.map((u) => (
          <li key={u.id}>
            {u.name}
            <button onClick={() => deleteItem("users", u.id)}>
              ❌
            </button>
          </li>
        ))}
      </ul>
    </div>
  );
}

🔔 Toast / Notification Integration

You can use:

  • react-hot-toast

One-time Setup for Toast

import { setupCrud } from "react-smart-crud";
import toast from "react-hot-toast";

setupCrud({
  baseUrl: "https://your-api.com",

  notify: (type, message) => {
    if (type === "success") toast.success(message);
    if (type === "error") toast.error(message);
  },
});

💡 Best Practices

✔ Keep mutations simple and rely on automatic refetch

✔ Handle toast in component, not inside library

✔ Use useCrud in multiple components — all stay in sync


✅ How it works (Mental Model)

Component
   ↓
useCrud("users")
   ↓
Global store cache
   ↓
API request (once)
   ↓
All subscribers auto update after mutations

👉 Multiple components → same data, no duplicate fetch