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

@jsonjoy.com/collaborative-react

v18.5.0

Published

JSON CRDT React.js hooks, components, and types

Readme

JSON CRDT integrations with React.js

React hooks, context helpers, and lightweight render-prop components for binding React UI to json-joy CRDT models and nodes.

Installation

npm install json-joy @jsonjoy.com/collaborative-react react

What this package provides

  • Context providers for Model and NodeApi
  • Reactive hooks for model ticks, model views, node views, and path access
  • Typed path hooks for object/array/string nodes
  • Render-prop components (UseModel, UseNode) for declarative subscriptions

Quick start

import * as React from 'react';
import {ModelCtx, useModelView, useStr} from '@jsonjoy.com/collaborative-react';
import {Model} from 'json-joy/lib/json-crdt';

const model = Model.create({title: 'Hello'});

function TitleEditor() {
	const root = useModelView();
	const title = useStr('/title');

	return (
		<div>
			<p>{root.title}</p>
			<button onClick={() => title?.ins(title.view().length, '!')}>Append !</button>
		</div>
	);
}

export const App = () => (
	<ModelCtx model={model}>
		<TitleEditor />
	</ModelCtx>
);

Context API

Providers

  • ModelCtx: provides a Model via context
  • NodeCtx: provides a NodeApi via context

When using ModelCtx, both the model and model.api are available to hooks.

Context hooks

  • useCtxModel() / useCtxNode(): optional context access (can return undefined)
  • useCtxModelStrict() / useCtxNodeStrict(): strict access (throws if missing)

Custom isolated context

Use createNodeCtx() when you need a separate, isolated node/model context in the same component tree.

Hooks

Model hooks

  • useModelTick(model?): subscribe to every model tick
  • useModelView(model?): subscribe to model view snapshot
  • useModel(selector, model?): derive reactive values from model
  • useModelTry(selector, model?): safe variant returning undefined on selector error

Node hooks

  • useNodeEvents(event, listener, node?): subscribe to node events (self, child, subtree)
  • useNodeEffect(event, listener, node?): effect wrapper with auto-unsubscribe
  • useNodeChange(event, node?): re-render on node change, returns last ChangeEvent
  • useNode(node?, event?): subscribe and return node
  • useNodeView(node?, event?): subscribe and return node view

Path hooks

  • usePath(path, node?, event?): read nested node by path
  • usePathView(path, node?, event?): read nested node view by path
  • useObj(path?, node?, event?): typed object node hook
  • useArr(path?, node?, event?): typed array node hook
  • useStr(path?, node?, event?): typed string node hook

Components

UseModel

Render-prop component that re-renders when model changes.

import {UseModel} from '@jsonjoy.com/collaborative-react';

<UseModel
	model={model}
	render={(m) => <pre>{JSON.stringify(m.api.view(), null, 2)}</pre>}
/>

UseNode

Render-prop component that re-renders on node events.

import {UseNode} from '@jsonjoy.com/collaborative-react';

<UseNode
	node={model.s.$}
	event="subtree"
	render={(node) => <pre>{JSON.stringify(node.view(), null, 2)}</pre>}
/>

Notes

  • Most hooks can infer the target model/node from context when used under ModelCtx or NodeCtx.
  • Use strict hooks only when you know a provider is present.
  • useModelView only re-renders when the view identity changes, while useModelTick re-renders on every model change.