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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@renchris/replicache-react

v6.1.0

Published

Miscellaneous utilities for using Replicache with React (React 19+ fork)

Readme

replicache-react

npm version

Provides a useSubscribe() hook for React which wraps Replicache's subscribe() method.

React 19+ Fork

This is a React 19+ compatible fork of the official replicache-react package. Key differences:

  • Removes deprecated batching APIs: No longer relies on unstable_batchedUpdates, leveraging React 19's automatic batching instead
  • Adds keepPreviousData option: Eliminates UI flash during navigation by preserving data across subscription transitions
  • Requires React 19+: Takes advantage of improved batching behavior in React 19

Installation

npm install @renchris/replicache-react
# or via GitHub
npm install renchris/replicache-react#feat/react-19-automatic-batching

Peer Dependencies: React 19+

Migration from Official Package

  1. Update to React 19+
  2. Replace replicache-react with @renchris/replicache-react in your package.json
  3. No code changes required - API is fully compatible
  4. Optional: Use new keepPreviousData option to prevent UI flash during navigation

API

function useSubscribe

React hook that allows you monitor replicache changes

| Parameter | Type | Description | | :--------------- | :------------------------------------------ | :------------------------------------------------------------------------------- | | rep | Replicache | Replicache instance that is being monitored | | query | (tx: ReadTransaction) => Promise<R> | Query that retrieves data to be watched | | options? | Object \| undefined | Option bag containing the named arguments listed below ⬇️ | | .default? | R \| undefined = undefined | Default value returned on first render or whenever query returns undefined | | .dependencies? | Array<any> = [] | List of dependencies, query will be rerun when any of these change | | .isEqual? | ((a: R, b: R) => boolean) = jsonDeepEqual | Compare two returned values. Used to know whether to refire subscription. | | .keepPreviousData? | boolean = true | When true (default), preserves previous data during dependency transitions to eliminate UI flash. Set to false to reset immediately. |

Usage

example of useSubscribe in todo app that is watching a specific category

const {category} = props;
const todos = useSubscribe(
  replicache,
  tx => {
    return tx
      .scan({prefix: `/todo/${category}`})
      .values()
      .toArray();
  },
  {
    default: [],
    dependencies: [category],
  },
);

return (
  <ul>
    {todos.map(t => (
      <li>{t.title}</li>
    ))}
  </ul>
);

New Feature: keepPreviousData

The keepPreviousData option (default: true) eliminates UI flash when navigating between views with different subscription dependencies.

Problem Without keepPreviousData

When switching between subscriptions (e.g., navigating between categories), the hook traditionally resets to undefined or the default value, causing a brief flash of empty content before new data loads:

// User switches from category "work" to "personal"
// 1. Hook unsubscribes from "work" data → returns default: []
// 2. UI renders empty list (FLASH!)
// 3. Hook subscribes to "personal" data
// 4. UI renders "personal" todos

Solution With keepPreviousData: true (Default)

The hook preserves the previous subscription's data while the new subscription initializes:

// User switches from category "work" to "personal"
// 1. Hook unsubscribes from "work" data → KEEPS "work" data displayed
// 2. Hook subscribes to "personal" data
// 3. UI renders "personal" todos (NO FLASH!)

Example

const todos = useSubscribe(
  rep,
  tx => getTodosByCategory(tx, category),
  {
    default: [],
    dependencies: [category],
    keepPreviousData: true, // Default - can be omitted
  }
);

// When category changes:
// - Old behavior: Shows [] briefly → new data
// - New behavior: Shows old data → new data (smooth transition)

When to Disable

Set keepPreviousData: false if you want to explicitly show the default value during transitions:

const todos = useSubscribe(
  rep,
  tx => getTodosByCategory(tx, category),
  {
    default: [],
    dependencies: [category],
    keepPreviousData: false, // Show [] during category switch
  }
);

Changelog

6.1.0 (React 19+ Fork)

  • NEW: Add keepPreviousData option (default: true) to eliminate UI flash during subscription transitions
  • Enhancement: Add generation counter to prevent stale subscription callbacks
  • Enhancement: Add isMounted guard to prevent setState after unmount
  • Enhancement: Improve type safety with Exclude<T, undefined> instead of conditional type
  • Enhancement: Add comprehensive JSDoc documentation with examples
  • Requires React 19+

6.0.0

Remove unstable_batchedUpdates - no longer needed with React 19's automatic batching. Requires React 19+. See https://react.dev/blog/2024/12/05/react-19

5.0.1

Change package to pure ESM. See See https://github.com/rocicorp/replicache-react/pull/61 for more information.

5.0.0

  • Add support for custom isEqual. See https://github.com/rocicorp/replicache-react/pull/59 for more information.
  • Requires Replicache 14.

4.0.1

Removes def from default dependencies. This is how it was before 0.4.0. Including by default makes it very easy to accidentally trigger render loops. People can added it explicitly if they really want.

4.0.0

This release changes the semantics of def slightly. In previous releases, def was returned only until query returned, then useSubscribe returns query's result. Now, def is returned initially, but also if query returns undefined.

This is an ergonomic benefit because it avoids having to type the default in two places. Before:

useSubscribe(r, tx => (await tx.get('count')) ?? 0, 0);

now:

useSubscribe(r, tx => tx.get('count'), 0);

3.1.0

Support a new generic form of ReadTransaction. New Replicaches and Reflects have tx.get<T> and tx.scan<T>. This update adds support for these to replicache-react. See: https://github.com/rocicorp/replicache-react/pull/55

3.0.0

Support (and require) Replicache 13.

2.11.0

When changing the value of r passed in, return the def value again, until the new subscription fires. See: https://github.com/rocicorp/replicache-react/commit/369d7513b09f48598db338c6776a9a22c7198e5c