
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
nanostores
Advanced tools
A tiny (265 bytes) state manager for React/Preact/Vue/Svelte with many atomic tree-shakable stores
Nanostores is a tiny state manager for React, Preact, Vue, Svelte, and vanilla JavaScript. It is designed to be small, fast, and efficient, making it suitable for both small and large applications. Nanostores provides a simple API for creating and managing reactive stores.
Creating a Store
Nanostores allows you to create a simple store using the `atom` function. This store can hold any type of data, and you can initialize it with a default value. In this example, a counter store is created with an initial value of 0.
import { atom } from 'nanostores';
const counter = atom(0);
Subscribing to a Store
You can subscribe to changes in a store using the `subscribe` method. This allows you to react to changes in the store's value. In this example, a subscription is set up to log the counter's value whenever it changes.
import { atom } from 'nanostores';
const counter = atom(0);
counter.subscribe(value => {
console.log('Counter value:', value);
});
Updating a Store
Nanostores provides a `set` method to update the value of a store. You can also use the `get` method to retrieve the current value of the store. In this example, the counter's value is incremented by 1.
import { atom } from 'nanostores';
const counter = atom(0);
counter.set(counter.get() + 1);
Zustand is a small, fast, and scalable state management solution for React. Like Nanostores, it provides a simple API for creating and managing state. However, Zustand is specifically designed for React, whereas Nanostores supports multiple frameworks including React, Vue, and Svelte.
Valtio is a proxy-based state management library for React. It allows you to create reactive state objects that automatically update components when the state changes. Valtio is similar to Nanostores in its simplicity and reactivity, but it is more focused on React and uses proxies for state management.
Jotai is a primitive and flexible state management library for React. It provides atoms as a way to manage state, similar to Nanostores. Jotai is designed to be minimal and composable, focusing on React applications, while Nanostores offers broader framework support.
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.
// 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.js'
export const $admins = computed($users, users => users.filter(i => i.isAdmin))
// components/admins.tsx
import { useStore } from '@nanostores/react'
import { $admins } from '../stores/admins.js'
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.
Read full docs here.
1.0.1
FAQs
A tiny (265 bytes) state manager for React/Preact/Vue/Svelte with many atomic tree-shakable stores
The npm package nanostores receives a total of 289,301 weekly downloads. As such, nanostores popularity was classified as popular.
We found that nanostores demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.