nanostores

A tiny (340 bytes) state manager for React/Preact/Vue/Svelte with many atomic tree-shakable stores

MIT 58 个版本
安装
npm install nanostores
yarn add nanostores
pnpm add nanostores
bun add nanostores
README

Nano Stores

A tiny state manager for React, React Native, Preact, Vue, Svelte, Solid, Lit, Angular, and vanilla JS. It uses many atomic stores and direct manipulation.

  • Small. Between 340 and 864 bytes (minified and brotlied). Zero dependencies. It uses [Size Limit] to control size.
  • Fast. With small atomic and derived stores, you do not need to call the selector function for all components on every store change.
  • Tree Shakable. A chunk contains only stores used by components in the chunk.
  • Designed to move logic from components to stores.
  • Good TypeScript support.
// store/users.ts
import { atom } from 'nanostores'

export const $users = atom<User[]>([])

export function addUser(user: User) {
  $users.set([...$users.get(), user])
}
// store/admins.ts
import { computed } from 'nanostores'
import { $users } from './users.ts'

export const $admins = computed($users, users => users.filter(i => i.isAdmin))
// components/admins.tsx
import { useStore } from '@nanostores/react'
import { $admins } from '../stores/admins.ts'

export const Admins = () => {
  const admins = useStore($admins)
  return (
    <ul>
      {admins.map(user => (
        <UserItem user={user} />
      ))}
    </ul>
  )
}

  Made at Evil Martians, product consulting for developer tools.


版本列表
1.4.0 2026-06-27
1.3.0 2026-04-17
1.2.0 2026-03-14
1.1.1 2026-02-25
1.1.0 2025-11-19
1.0.1 2025-04-10
1.0.0 2025-04-10
0.11.4 2025-02-14
0.11.3 2024-08-26
0.11.2 2024-08-05
0.11.1 2024-08-05
0.11.0 2024-08-03
0.10.3 2024-04-05
0.10.2 2024-04-01
0.10.1 2024-04-01
0.10.0 2024-02-20
0.9.5 2023-11-10
0.9.4 2023-10-15
0.9.3 2023-06-29
0.9.2 2023-06-14
0.9.1 2023-05-28
0.9.0 2023-05-24
0.8.1 2023-04-26
0.8.0 2023-04-13
0.7.4 2023-02-17
0.7.3 2023-02-02
0.7.2 2023-02-02
0.7.1 2022-11-13
0.7.0 2022-09-09
0.6.0 2022-07-30
0.5.13 2022-07-29
0.5.12 2022-03-12
0.5.11 2022-03-11
0.5.10 2022-02-03
0.5.9 2022-02-01
0.5.8 2021-12-10
0.5.7 2021-11-29
0.5.6 2021-11-05
0.5.5 2021-11-05
0.5.4 2021-10-26
0.5.3 2021-10-22
0.5.2 2021-10-22
0.5.1 2021-10-21
0.5.0 2021-10-21
0.4.9 2021-10-11
0.4.8 2021-09-05
0.4.7 2021-09-03
0.4.6 2021-09-03
0.4.5 2021-08-31
0.4.4 2021-08-31
0.4.3 2021-08-09
0.4.2 2021-08-09
0.4.1 2021-07-25
0.4.0 2021-07-25
0.3.3 2021-06-09
0.3.2 2021-06-03
0.3.1 2021-06-03
0.3.0 2021-06-02