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-storage-drafts

v1.1.0

Published

React Drafts is a library for creating, saving, and managing local documents in React applications.

Readme

react-storage-drafts

react-storage-drafts is a lightweight, flexible React context provider for managing, storing, and syncing local drafts (e.g. offline forms, notes, cached edits) with optional syncing strategies like intervals, connection changes, or manual triggers.


🚀 Features

  • Store drafts locally in memory
  • Add, update, and remove drafts
  • Sync unsynced drafts with external storage
  • Configurable sync triggers: onChange, interval, connection, or manual
  • Optional integration with online/offline detection (via navigator.onLine or React Native NetInfo)

📦 Installation

npm install react-storage-drafts

or

yarn add react-storage-drafts

🔧 Usage

1. Wrap your app with the Provider

import { Provider } from 'react-storage-drafts';

<Provider
  referenceKey="id"
  syncTrigger="connection" // or 'onChange' | 'interval' | 'manual'
  syncInterval={60} // optional, in seconds
  onSync={async (drafts) => {
    // Sync changed drafts to external storage (e.g. API)
    // Drafts will have a status property: 'changed' | 'removed'
    await api.saveDrafts(drafts);
  }}
  onLoadStoredData={async () => {
    return await api.loadDrafts();
  }}
>
  <YourApp />
</Provider>

2. Access drafts with useDrafts hook

import { useDrafts } from 'react-storage-drafts';

const { drafts, count, addDraft, updateDraft, removeDraft, clearDrafts } = useDrafts();

// Example:
addDraft({ id: 'draft-1', title: 'New Draft' });

🧠 API Reference

<Provider />

| Prop | Type | Required | Description | |--------------------|----------------------------------|----------|-------------| | referenceKey | string | ❌ | Key used to identify and manage each draft. If not provided, _duid autogenerated property will be used. | | syncTrigger | 'onChange' \| 'interval' \| 'connection' \| 'manual' | ✅ | Determines when to trigger syncing. | | syncInterval | number | ❌ | Sync interval (in seconds) if syncTrigger is 'interval'. Defaults to 120. | | onSync | (drafts: any[]) => void \| Promise<void> | ✅ | Callback to sync unsynced drafts to external storage. Unsyced drafts will have changed (new/modified) or removed status | | onLoadStoredData | () => Promise<any[]> | ❌ | Callback to load initial data into the context. |


useDrafts Hook

Use useDrafts() to access these values:

{
  drafts: any[];
  count: number;
  addDraft: (draft: any) => void;
  updateDraft: (key: string | number, changes: any) => void;
  removeDraft: (key: string | number) => void;
  clearDrafts: () => void;
  handleSync: () => void; // Manually trigger sync (if set 'manual' syncTrigger in provider)
}

useDraft Hook

Use useDraft({ draftId: '' }) to manage a single draft: draftId is the key of the draft you want to manage. Setting draftId to first or last will return the first or last draft in the list, respectively.

{
  draft: any;
  update: (changes: any) => void;
  remove: () => void;
}

🧪 Sync Triggers

  • onChange: Syncs immediately after adding/updating/removing a draft.
  • interval: Syncs every syncInterval seconds.
  • connection: Syncs automatically when the app goes online.
  • manual: You can call the exposed syncData manually (exposing this is coming soon).

🌐 Online Detection

When using syncTrigger="connection", the provider uses the useOnline hook to detect if the app is online.

Web: uses navigator.onLine and online/offline events

React Native: uses @react-native-community/netinfo


📁 File Structure

src/
├── Provider.tsx         # The main context provider
├── Context.ts           # React Context object
├── useOnline.ts         # Hook for online status
├── useDrafts.ts         # Hook for drafts management
├── types.ts             # Type declarations

📝 License

MIT © BossBele


💬 Contributing / Issues

PRs and issues are welcome! Open an issue on the GitHub repo.


🛠️ TODOs

  • [x] Expose manual sync method
  • [ ] Add persistent storage with localStorage/AsyncStorage
  • [ ] Bundle as ESM + CJS for wider compatibility