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

atom-context

v0.9.0

Published

A simple react context that work in RSC and client components.

Readme

atom-context

Tiny typed context atoms for React Server Components and Client Components.

atom-context gives you a small per-request store for RSC and a matching client-side atom so values can be initialized on the server, passed through a client boundary, and read or updated by client components without wiring a React context provider tree.

Installation

pnpm add atom-context @nanostores/react

React 19 or newer is required. @nanostores/react is used by the examples below to subscribe to client atoms from React components.

What It Provides

  • getServerContextAtom from atom-context/server: a server-only per-request atom backed by React cache.
  • AtomContextProvider from atom-context: a client component that seeds a client atom from a server value.
  • getClientContextAtom from atom-context: a client-side Nanostores atom for reading and updating the value by key.

The server helper is exported from atom-context/server so server-only code stays out of the client-safe root entrypoint.

Usage

Create a shared key and type for the value you want to pass through the tree.

// user-context.ts
export type UserContext = {
  id: string
  name: string
}

export const userContextKey = "app:user"

Seed the value in a Server Component and bridge it to client components with AtomContextProvider.

// app/layout.tsx
import { AtomContextProvider } from "atom-context"
import { getServerContextAtom } from "atom-context/server"

import { userContextKey, type UserContext } from "./user-context"

export default async function RootLayout({ children }: { children: React.ReactNode }) {
  const user: UserContext = await getCurrentUser()
  const userAtom = getServerContextAtom(userContextKey, user)

  return (
    <html>
      <body>
        <AtomContextProvider contextKey={userContextKey} serverValue={userAtom.value}>
          {children}
        </AtomContextProvider>
      </body>
    </html>
  )
}

Read the same value later in another Server Component during the same request.

// app/profile/page.tsx
import { getServerContextAtom } from "atom-context/server"

import { userContextKey, type UserContext } from "../user-context"

export default function ProfilePage() {
  const user = getServerContextAtom<UserContext>(userContextKey)

  return <h1>{user.value.name}</h1>
}

Read and update the bridged atom from a Client Component.

"use client"

import { getClientContextAtom } from "atom-context"
import { useStore } from "@nanostores/react"

import { userContextKey, type UserContext } from "./user-context"

export function UserBadge() {
  const store = getClientContextAtom<UserContext>(userContextKey, {
    id: "anonymous",
    name: "Anonymous",
  })

  const user = useStore(store)

  return <span>{user.name}</span>
}

API

getServerContextAtom<T>(key, defaultValue?)

Creates or reads a server-only atom for the current RSC request. Passing defaultValue seeds the value for that key. Reading the same key later in the same request returns the same atom value, while concurrent requests stay isolated from each other.

const theme = getServerContextAtom("theme", "dark")
theme.value = "light"

AtomContextProvider

A client component that writes a server value into the matching client atom and keeps it in sync when serverValue changes.

<AtomContextProvider contextKey="theme" serverValue="dark">
  {children}
</AtomContextProvider>

getClientContextAtom<T>(key, initial)

Returns the client-side Nanostores WritableAtom instance for a key. The same key always returns the same atom instance. Use store.get(), store.set(value), and store.subscribe(listener) directly, or connect it to React with useStore from @nanostores/react.

Notes

  • Use stable, unique keys to avoid collisions between unrelated values.
  • Import getServerContextAtom only from Server Components, server utilities, or files that already run under the React server condition.
  • Values are not reactive inside an already-rendered Server Component. If you mutate .value, read it again from the atom when you need the latest value.

Acknowledgement

The server-side atom approach was inspired by Jonathan Gamble's article Easy Context in React Server Components (RSC).