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-input-react

v18.28.0

Published

CollaborativeInput React component, binds DOM input or textarea elements to a JSON CRDT str node

Readme

<CollaborativeInput> React Component

A React component that binds DOM <input> and <textarea> elements to JSON CRDT str nodes, enabling seamless collaborative editing with automatic synchronization across multiple users.

Features

  • Collaborative Editing: Bind HTML <input> or <textarea> elements to JSON CRDT data structures for real-time multi-user editing
  • Automatic Synchronization: Changes in the DOM automatically sync to the CRDT model and vice versa
  • Flexible Integration: Use as a controlled component or with custom input elements
  • Polling Support: Optional polling for detecting third-party modifications to input elements

Installation

npm install @jsonjoy.com/collaborative-input-react

Basic Usage

Simple Input Example

import React from 'react';
import {Model} from 'json-joy/lib/json-crdt';
import {CollaborativeInput} from '@jsonjoy.com/collaborative-input-react';

export const MyComponent = () => {
  const model = React.useMemo(() => Model.create(), []);

  return (
    <CollaborativeInput
      str={() => model.api.str(['myText'])}
      placeholder="Type here..."
    />
  );
};

Textarea Example

<CollaborativeInput
  str={() => model.api.str(['description'])}
  multiline
  placeholder="Enter multi-line text..."
/>

Custom Input Element

You can provide a custom React component which renders the <input> or <textarea> elements, you just need to connect the ref to the underlying DOM element using the input prop:

<CollaborativeInput
  str={() => model.api.str(['myText'])}
  input={(connect) => (
    <input
      ref={connect}
      type="text"
      className="my-custom-input"
    />
  )}
/>

Props

CollaborativeInputProps

| Prop | Type | Default | Description | |------|------|---------|-------------| | str | () => CollaborativeStr | required | Function returning the JSON CRDT str node to bind | | multiline | boolean | false | When input prop is not provided, determines whether to render <input> or <textarea> | | polling | boolean | false | Enable polling for updates when third-party code modifies the input element's value | | input | (ref) => React.ReactNode | - | Custom render function for the input element | | inp | (el) => void | - | Callback ref to access the DOM element | | ...rest | React.InputHTMLAttributes | - | Standard HTML input/textarea attributes (className, placeholder, etc.) |

Advanced Usage

With Polling

Normally you never need polling. But if you know some JavaScript can modify the underlying input DOM element, you can enable polling to detect such changes:

<CollaborativeInput
  str={() => model.api.str(['myText'])}
  polling={true}
/>

Accessing the DOM Element

const inputRef = React.useRef<HTMLInputElement>(null);

<CollaborativeInput
  str={() => model.api.str(['myText'])}
  inp={(el) => {
    if (inputRef.current) {
      inputRef.current = el;
    }
  }}
/>

Programmatic Updates

const handleClick = () => {
  const str = model.api.str(['myText']);
  str.ins(str.view().length, '!');
};

How It Works

The CollaborativeInput component:

  1. Creates a binding between the HTML input/textarea element and a JSON CRDT str node
  2. Listens to DOM input events and synchronizes changes to the CRDT model
  3. Subscribes to model updates and reflects them in the DOM element
  4. Automatically unbinds when the component unmounts
  5. Optionally polls for changes detected by external code

Related Packages

See Also