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

atomtree

v1.0.3

Published

A tiny global state management library for React.

Readme

atomtree

A tiny library for global state management in React. ~1kb minified (and less gzipped).

Features

  • Full type safety for end users.
  • Full server rendering support with no need to wrap your server in a context.
  • Full utilisation of functionality built into React.
  • A simple API for creating atoms, using them as a group, and setting them from an object (useful for setting state from an API response for example).

"Talk is cheap, show me the code"

The entire library (without types) is ~130 lines of code and is in the index.mjs file. The types and documentation for each function are in the index.d.ts file. If you want to see examples of how to use the library, you can check out the examples folder.

For context of how this all works, atomtree is built on the idea that you will have an object that repersents your state structure. In this example, it might look something like this:

export const state = {
    shoppingCart: {
        items: atom<Item[]>([]),
        referralCode: atom<string | null>(null),
    },
    user: atom<User | null>(null),
};

You should group things together that you might want to view at the same time in the future. Functions do not live here, rather the state is purely the data.

If we want to use an individual atom, we can do so like this in a React component:

const user = state.user.use();

You may notice that we don't have a setter here. This is very intentional! You can freely set and mutate outside of the context of React. Each atom has the following functions:

  • use(): T: A hook that returns the current value of the atom. Covered above.
  • nonReactGet(): T: A function that returns the current value of the atom. This is useful if you want to get the value of an atom outside of a React component.
  • set(value: T): A function that sets the value of the atom. If the value is different to the current value, any components that are using the atom will re-render.
  • mutate(fn: (value: T) => void): A function that mutates the value of the atom. It is presumed the value has been changed in some way, so the atom will re-render any components that are using it.

To mutate the state, we can simply write a function that doesn't need to be called within React context to do so:

export function pushShoppingCartItem(item: Item) {
    state.shoppingCart.items.mutate((items) => {
        items.push(item);
    });
}

You can also set an individual atom in a similar way:

export function setShoppingCartReferralCode(code: string) {
    state.shoppingCart.referralCode.set(code);
}

This will cause all components using this array to re-render. But what if we want to set the state from an API response or local storage (or something like that)? We can do so with the setStructureFromObject function:

setStructureFromObject(state.shoppingCart, {
    items: [...],
    referralCode: "not-honey",
});

But what if we want a cluster of atoms at the same time when we render? Assuming all the ones you want to render are grouped together, you can use the useAtomsFromStructure function:

const { items, referralCode } = useAtomsFromStructure(state.shoppingCart);

This will automatically subscribe to all the atoms in the structure and re-render when any of them change.