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

@happylinks/roomservice-react

v0.4.12

Published

The `@roomservice/react` library is the main JS library for RoomService. You should use it _with_ the `@roomservice/browser` library.

Readme

@roomservice/react

The @roomservice/react library is the main JS library for RoomService. You should use it with the @roomservice/browser library.

Installing

npm install --save @roomservice/react@next

or, with yarn:

yarn add @roomservice/react@next

Usage

Setup a <RoomServiceProvider />

At the top of your app, add a RoomServiceProvider with your auth endpoint.

import { RoomServiceProvider } from "@roomservice/react";

function App() {
  return (
    <RoomServiceProvider authUrl="https://yoursite.com/api/roomservice">
      <CollaborativeComponent />
    </RoomServiceProvider>
  );
}

export default App;

useSharedState

Shared state lets you and other folks in the room collaborate on the same JSON state. Shared state has a built-in CRDT and offline support, so you can assume that merges will happen automatically, deterministically, and without the need for constant internet connection.

import { useSharedState } from "@roomservice/react";

function MyComponent() {
  const [sharedState, setSharedState] = useSharedState("my-room");

  function onChange() {
    setSharedState(prevState => {
      prevState.myOption = "hello!";
    });
  }

  // ...
}

Rules of sharedState

Rule 1: only use a function parameter. Unlike the regular setState, setSharedState only supports a function as an argument, not an object.

For example:

// BAD - not allowed
setSharedState({
  title: "hello!"
});

// GOOD - this works
setSharedState(prevState => {
  prevState.title = "hello!";
});

Rule 2: don't return anything. As you may have noticed, the function you pass into setSharedState does not return anything from the document like setState does. Instead, it works like Immer does; you mutate the object itself.

For example:

// BAD - don't return
setSharedState(prevState => {
  return {
    ...prevState,
    title: "hello!"
  };
});

// GOOD - mutate the object instead
setSharedState(prevState => {
  prevState.title = "hello!";
});

Rule 3: only JSON primitives. Don't pass classes, functions, or React components into your shared state. Only JSON primitives, like lists, numbers, strings, and maps work. As a rule of thumb, if it wouldn't be valid in someFile.json, it won't be valid in Room Service.

For example:

class MyBike {
  zoom() {}
}

// BAD - this won't work like you expect
setSharedState(prevState => {
  prevState.bike = new MyBike();
});

usePresence

Presence is temporary state for each individual user in a room that, like shared-state, updates automatically. Presence is not stored in a CRDT and does not do automatic merging.

Unlike shared state, presence has extremely low latency, which makes it perfect for:

  • Mouse cursors
  • GPS locations
  • the cell position in a table
  • device info
  • the tab someone's on
  • ???
import { usePresence } from "@roomservice/react";

const [positions, setMyPosition] = usePresence("my-room", "cell-positions");

// Set your presence.
setMyPosition({
  x: 0,
  y: 10
});

// Access other user's presence
const { x, y } = positions["my-user-reference"];

Note that presence returns an object, not an array. So if you want to iterate through multiple folks presences, you should use Object.values.

function MapPins() {
  const [locations, setMyPresence] = usePresence("my-room", "locations");

  Object.values(locations).map(location => {
    return <Pin lat={location.lat} long={location.long} >
  })
}

Presence is meant to be a primitive to make other declarative real-time features. So get creative and make your own custom hooks!