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

usewatch-js

v1.1.0

Published

Lightweight reactive state management for vanilla JavaScript with local, named and contextual stores, and optional cross-tab synchronization.

Readme

usewatch-js

Minimal reactive state for modern JavaScript.

Small, framework-free state primitives for local state, shared contexts and optional cross-tab sync.

Index

Overview

usewatch-js is a small reactive state library for vanilla JavaScript and TypeScript.

  • No DOM bindings
  • No framework adapters
  • No official React/Vue wrappers
  • Small public API
  • Optional BroadcastChannel sync for named states

This repository only contains the library. The full documentation site will live in a separate dev-hub project.

Installation

npm install usewatch-js
<script src="https://unpkg.com/usewatch-js/dist/usewatch-js.min.js"></script>
<script>
  const count = usewatchJs.setState(0);

  usewatchJs.useWatch((state) => {
    console.log(state.value);
  }, [count]);

  count.value += 1;
</script>
<script type="module">
  import { setState, useWatch } from "https://unpkg.com/usewatch-js/dist/index.js";

  const count = setState(0);

  useWatch((state) => {
    console.log(state.value);
  }, [count]);

  count.value += 1;
</script>

Basic Usage

import { setState, useWatch } from "usewatch-js";

const count = setState(0);

useWatch((state) => {
  console.log("count:", state.value);
}, [count]);

count.value += 1;
import { createContext } from "usewatch-js";

const app = createContext();
const theme = app.useState("theme", "dark");

app.useWatch((state) => {
  console.log("theme:", state.value);
}, [theme]);

Local State

Use setState(value) for a local anonymous state.

import { setState, useWatch } from "usewatch-js";

const count = setState(0);

useWatch((state) => {
  console.log(state.value);
}, [count]);

count.value++;

Named State

Use useState(key, initialValue?) when you want to create or recover a named state.

import { useState } from "usewatch-js";

const user = useState("user", { name: "John" });

user.value.name = "Jane";

console.log(user.value.name);

createContext

Use createContext() to isolate a state registry and its watchers.

import { createContext } from "usewatch-js";

const app = createContext();

const count = app.setState(0);
const theme = app.useState("theme", "dark");

app.useWatch((countState, themeState) => {
  console.log(countState.value, themeState.value);
}, [count, theme]);

Sync Between Tabs

Named states can synchronize between tabs with BroadcastChannel.

  • Same origin only
  • No persistence
  • Good for lightweight tab-to-tab updates
import { useState } from "usewatch-js";

const theme = useState("theme", "dark", {
  syncTabs: true,
});

theme.value = "light";

API Overview

  • setState: creates a local state or creates/updates a named state when used with a key.
  • useState: gets or creates a named state in the current context.
  • useWatch: subscribes to one or more states and returns an unsubscribe function.
  • createContext: creates an isolated state registry with its own setState, useState and useWatch.

Contributing

See CONTRIBUTING.md for setup, workflow and contribution guidelines.

License

MIT. See LICENSE.md.