
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
nanostores
Advanced tools
A tiny (199 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, 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, list =>
list.filter(user => user.isAdmin)
)
// components/admins.tsx
import { useStore } from '@nanostores/react'
import { admins } from '../stores/admins.js'
export const Admins = () => {
const list = useStore(admins)
return (
<ul>
{list.map(user => <UserItem user={user} />)}
</ul>
)
}
Read full docs on GitHub.
0.5.7
Atom#notify()
types (by Aleksandr Slepchenkov).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 97,377 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 0 open source maintainers 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.