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

@docstack/react

v0.0.9

Published

One does not simply stack documents.

Readme

@docstack/react

React bindings for DocStack Client, enabling seamless integration of the intelligent, offline-first database engine into React applications.

This package provides a context provider and hooks to initialize the database, subscribe to data changes, and perform write operations.

📦 Installation

npm install @docstack/react @docstack/client

🚀 Usage

1. Setup the Provider

Wrap your application root with <StackProvider>. This component initializes the DocStack engine and applies any schema patches provided in the configuration.

import { StackProvider } from "@docstack/react";

const DB_NAME = 'my-app-db';

// Define schema patches (versioned changes to your data model)
const PATCHES = [
  {
    "~class": "patch",
    version: "1.0.0",
    active: true,
    docs: [
      {
        _id: "Todo",
        "~class": "class",
        name: "Todo",
        schema: {
          title: { name: "title", type: "string", config: { mandatory: true } },
          completed: { name: "completed", type: "boolean", config: { defaultValue: false } }
        }
      }
    ]
  }
];

function App() {
  return (
    <StackProvider config={[{ name: DB_NAME, patches: PATCHES }]}>
      <MyComponent />
    </StackProvider>
  );
}

2. Read Data (Reactive)

Use the useClassDocs hook to fetch documents for a specific class. This hook automatically subscribes to changes, so your component re-renders whenever the underlying data changes.

import { useClassDocs } from "@docstack/react";

function TodoList() {
  // Fetch all documents of class 'Todo' from 'my-app-db'
  const { docs: todos, loading } = useClassDocs('my-app-db', 'Todo');

  if (loading) return <p>Loading...</p>;

  return (
    <ul>
      {todos.map(todo => (
        <li key={todo._id}>
          {todo.title} {todo.completed ? '✅' : '⭕'}
        </li>
      ))}
    </ul>
  );
}

3. Write Data

Use the useDocStack hook to access the underlying DocStack client instance for creating, updating, or deleting data.

import { useState } from 'react';
import { useClass } from "@docstack/react";

function AddTodo() {
  const { classObj: todoClass } = useClass('my-app-db', 'Todo');
  const [title, setTitle] = useState("");

  const handleAdd = async () => {
    if (!todoClass || !title) return;
    
    // Add the new document
    await todoClass.add({ title, completed: false });
    
    setTitle("");
  };

  return (
    <div>
      <input value={title} onChange={e => setTitle(e.target.value)} />
      <button onClick={handleAdd}>Add Task</button>
    </div>
  );
}

📚 API Reference

<StackProvider />

The context provider that manages the lifecycle of the DocStack client.

| Prop | Type | Description | |------|------|-------------| | config | Array<{ name: string, patches: any[] }> | Configuration for initializing stacks, including database names and schema patches. |

useClassDocs(dbName: string, className: string)

A hook that subscribes to a specific class in the database.

  • Arguments:
    • dbName: The name of the database stack.
    • className: The name of the class to query.
  • Returns:
    • docs: An array of documents belonging to the class.
    • loading: A boolean indicating if the initial data load is in progress.

useClass(dbName: string, className: string)

A hook that retrieves the class definition for writing data.

  • Arguments:
    • dbName: The name of the database stack.
    • className: The name of the class.
  • Returns:
    • classObj: The class instance used for operations like add or updateCard.
    • loading: Boolean indicating if the class is loading.

useDocStack()

A hook that returns the initialized DocStack client instance.

  • Returns: The DocStack instance (or null if not yet initialized). Use this to access getStack(), run queries, or execute jobs.

useQuerySQL(dbName: string, sql: string, ...params: any[])

A hook to execute SQL queries against the local database.

  • Arguments:
    • dbName: The name of the database stack.
    • sql: The SQL query string.
    • params: Variable arguments for query parameters.
  • Returns:
    • result: An object containing rows (the query results).
    • loading: Boolean indicating execution status.

useFind(dbName: string, query: { selector: object, fields?: string[] })

A hook to find documents using a MongoDB-style selector.

  • Arguments:
    • dbName: The name of the database stack.
    • query: An object with a selector property (Mango query syntax).
  • Returns:
    • docs: An array of matching documents.
    • loading: Boolean indicating if the search is in progress.

useClassList(dbName: string, selector: object)

A hook to retrieve a list of available classes (schemas) in the database.

  • Arguments:
    • dbName: The name of the database stack.
    • selector: A filter object to select specific classes.
  • Returns:
    • classList: An array of Class instances.
    • loading: Boolean indicating if the list is loading.

useClassCreate(dbName: string)

A hook that returns a function to create new classes dynamically.

  • Arguments:
    • dbName: The name of the database stack.
  • Returns:
    • A function (className: string, description?: string) => Promise<Class> to create a new class.