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

@nexus-state/react

v0.1.14

Published

> React integration for Nexus State — fine-grained reactivity with split read/write hooks > > [![npm version](https://img.shields.io/npm/v/@nexus-state/react)](https://www.npmjs.com/package/@nexus-state/react) > [![Coverage for react package](https://cove

Readme

@nexus-state/react

React integration for Nexus State — fine-grained reactivity with split read/write hooks

npm version Coverage for react package npm downloads License

DocumentationRepository


🚀 Quick Start (60 seconds)

import { atom, createStore } from '@nexus-state/core';
import { useAtom } from '@nexus-state/react';

// Create atom and store
const countAtom = atom(0, 'count');
const store = createStore();

function Counter() {
  const [count, setCount] = useAtom(countAtom, store);
  
  return (
    <button onClick={() => setCount(c => c + 1)}>
      {count}
    </button>
  );
}

Minimum required: React 17.0.0


🎯 Why Nexus State for React?

Comparison with Native Solutions

| Feature | Nexus State | Jotai | Zustand | Redux Toolkit | |---------|-------------|-------|---------|---------------| | Split hooks | ✅ useAtomValue + useSetAtom | ⚠️ Limited | ❌ | ❌ | | No Provider required | ✅ Optional | ❌ Required | ❌ Required | ❌ Required | | Fine-grained updates | ✅ Per-atom | ✅ | ❌ Store-wide | ❌ Store-wide | | Multi-framework | ✅ React/Vue/Svelte | ❌ React-only | ✅ | ✅ | | Bundle size | 2.1KB | 3.2KB | 1KB | 13KB | | DevTools | ✅ Redux DevTools | ✅ | ✅ Custom | ✅ |

✅ Choose Nexus State if you need:

  • Fine-grained reactivity (per-atom updates)
  • Split read/write hooks for optimization
  • Multi-framework state sharing
  • Isolated stores (SSR, testing)

❌ Use alternatives if:

  • Simple global state → Zustand (lighter)
  • React-only project → Jotai (simpler API)
  • Redux ecosystem → Redux Toolkit (more plugins)

📖 Core Hooks

useAtom(atom, store?)

Read + write access to an atom.

import { useAtom } from '@nexus-state/react';

function Counter() {
  const [count, setCount] = useAtom(countAtom, store);
  
  return (
    <div>
      <p>{count}</p>
      <button onClick={() => setCount(c => c + 1)}>+</button>
    </div>
  );
}

useAtomValue(atom, store?)

Read-only access (optimized — no setter created).

import { useAtomValue } from '@nexus-state/react';

function Display() {
  const count = useAtomValue(countAtom, store);
  // Component won't re-render from setter changes
  return <p>{count}</p>;
}

useSetAtom(atom, store?)

Write-only access (optimized — no subscription).

import { useSetAtom } from '@nexus-state/react';

function IncrementButton() {
  const setCount = useSetAtom(countAtom, store);
  // Component never re-renders from atom changes!
  return <button onClick={() => setCount(c => c + 1)}>+</button>;
}

Split Hooks Pattern (Optimized Forms)

import { atom, createStore } from '@nexus-state/core';
import { useAtomValue, useSetAtom } from '@nexus-state/react';

const nameAtom = atom('', 'name');
const emailAtom = atom('', 'email');
const store = createStore();

// Input component — write-only (no re-renders)
function NameInput() {
  const setName = useSetAtom(nameAtom, store);
  return <input onChange={e => setName(e.target.value)} />;
}

// Display component — read-only
function NameDisplay() {
  const name = useAtomValue(nameAtom, store);
  return <p>Name: {name}</p>;
}

// Components update independently!
function Form() {
  return (
    <form>
      <NameInput />
      <NameDisplay />
    </form>
  );
}

useAtomCallback(get, set, store?)

Complex operations with multiple atoms.

import { useAtomCallback } from '@nexus-state/react';

function TransferButton() {
  const handleTransfer = useAtomCallback(
    (get, set, amount: number) => {
      const balance = get(balanceAtom);
      if (balance >= amount) {
        set(balanceAtom, balance - amount);
        set(logAtom, [...get(logAtom), `Transferred ${amount}`]);
      }
    },
    store
  );

  return <button onClick={() => handleTransfer(100)}>Transfer</button>;
}

StoreProvider (Optional)

import { StoreProvider } from '@nexus-state/react';

const store = createStore();

function App() {
  return (
    <StoreProvider store={store}>
      <Counter /> {/* Can use hooks without explicit store */}
    </StoreProvider>
  );
}

// In component
function Counter() {
  const [count, setCount] = useAtom(countAtom); // store from context
}

🔌 Integration with Ecosystem

Data Fetching (@nexus-state/query)

import { useQuery } from '@nexus-state/query/react';
import { useAtomValue } from '@nexus-state/react';

function UserProfile() {
  const userId = useAtomValue(userIdAtom, store);
  
  const { data: user, isLoading } = useQuery({
    queryKey: ['user', userId],
    queryFn: fetchUser,
  });
  
  if (isLoading) return <div>Loading...</div>;
  return <div>{user.name}</div>;
}

📖 Full docs: npm


Persistence (@nexus-state/persist)

import { persistAtom } from '@nexus-state/persist';
import { useAtomValue } from '@nexus-state/react';

// Persist atom to localStorage
const settingsAtom = persistAtom(
  { theme: 'light' },
  'settings',
  { storage: 'localStorage' }
);

function Settings() {
  const settings = useAtomValue(settingsAtom, store);
  return <div>Theme: {settings.theme}</div>;
}

📖 Full docs: npm


Async Atoms (@nexus-state/async)

import { asyncAtom } from '@nexus-state/async';
import { useAtomValue } from '@nexus-state/react';

const [userAtom, fetchUser] = asyncAtom({
  fetchFn: async (id: number) => fetch(`/api/users/${id}`).then(r => r.json()),
  initialValue: null,
});

function UserProfile({ userId }) {
  const { data: user, isLoading } = useAtomValue(userAtom, store);
  
  if (isLoading) return <div>Loading...</div>;
  return <div>{user.name}</div>;
}

📖 Full docs: npm


📚 API Reference

| Hook | Signature | Description | |------|-----------|-------------| | useAtom | useAtom(atom, store?) | Read + write | | useAtomValue | useAtomValue(atom, store?) | Read only (optimized) | | useSetAtom | useSetAtom(atom, store?) | Write only (no re-render) | | useAtomCallback | useAtomCallback(fn, store?) | Complex operations | | StoreProvider | <StoreProvider store> | Context provider | | useStore | useStore() | Get store from context |


🔧 Troubleshooting

1. "useAtom requires a store" error

Cause: Store not provided and no StoreProvider.

Solution:

// Option 1: Provide store explicitly
const [count] = useAtom(countAtom, store);

// Option 2: Use StoreProvider
<StoreProvider store={store}>
  <Component />
</StoreProvider>

2. Component not re-rendering on atom changes

Cause: Using useSetAtom (by design — no subscription).

Solution: Use useAtom or useAtomValue for read access.

// ❌ Won't re-render
const setCount = useSetAtom(countAtom);

// ✅ Will re-render
const [count, setCount] = useAtom(countAtom);

3. Stale closure in callbacks

Cause: Callback captures old atom values.

Solution: Use useAtomCallback with get/set.

// ❌ Stale closure
const handleClick = () => {
  setCount(count + 1); // May be stale
};

// ✅ Fresh values
const handleClick = useAtomCallback((get, set) => {
  set(countAtom, get(countAtom) + 1);
});

📦 Related Packages

| Package | Description | npm | |---------|-------------|-----| | @nexus-state/core | Core concepts (atoms, stores) | Install | | @nexus-state/query | Data fetching & caching | Install | | @nexus-state/async | Simple async state | Install | | @nexus-state/persist | LocalStorage persistence | Install | | @nexus-state/form | Form management | Install | | @nexus-state/devtools | Redux DevTools integration | Install |


🔗 See Also

Full ecosystem: Nexus State Packages


📄 License

MIT