nanostores

v1.2.0 MIT

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

Weekly Downloads
1.9M
Stars
7.2K
Forks
141
Open Issues
23
Gzip Size
2.0 kB
Unpacked Size
48.4 kB
Dependencies
1
Last Updated
1mo ago

nanostores Download Trends

Download trends for nanostores02.3M4.6M6.9M9.2MFeb 2025MayAugNovFebApr 2026
nanostores

About nanostores

Nanostores is a minimalist state management library designed to provide an extremely small footprint for modern web applications. It addresses the complexity and bundle size concerns often associated with larger state management solutions by offering a highly optimized and atomic approach to managing application state. Its core goal is to deliver essential state management capabilities with minimal overhead, making it suitable for performance-sensitive projects.

The library's philosophy centers around simplicity and granular control over state updates. It's built for developers who need an efficient way to handle shared state across components without introducing significant build sizes or performance penalties, particularly in frameworks like React, Preact, Vue, and Svelte.

Key to Nanostores' API is the concept of atomic stores, which are small, independent units of state. You create these stores using functions like `atom()` or `map()`, allowing for fine-grained subscriptions to state changes. This atomic nature also means that only the parts of your application that rely on a specific store will be re-rendered when that store updates, enhancing performance through efficient re-renders and excellent tree-shakability.

Nanostores integrates seamlessly with popular frontend frameworks. It provides specific bindings or hooks for React and Preact (like `useStore()`) and can be easily adopted in Vue and Svelte projects using their respective reactivity mechanisms. Its low-level nature means it can also be used with vanilla JavaScript or other build tools.

With a bundle size of just 2.0 kB (gzipped) and a core size of 271 bytes, Nanostores offers exceptional performance characteristics. This small footprint minimizes load times and improves application responsiveness. The library is actively maintained, indicated by its recent update, and has a substantial download count, suggesting widespread adoption and community trust.

Developers should be aware that Nanostores' minimalist design means it does not include built-in features for complex asynchronous operations or advanced middleware functionalities found in larger state managers. While powerful for its intended purpose, managing intricate side effects might require integrating additional patterns or libraries, and its atomic nature requires careful consideration for structuring complex, interconnected state.

When to use

  • When minimizing JavaScript bundle size is a critical project requirement.
  • For applications built with React, Preact, Vue, or Svelte that need efficient, atomic state updates.
  • When you want to leverage granular subscriptions to ensure only relevant components re-render upon state changes.
  • For managing shared state in performance-critical sections of an application that cannot tolerate larger state management libraries.
  • When building UI components that react to external data sources, leveraging its `listen()` API for responsiveness.
  • For projects prioritizing tree-shakability to ensure unused parts of the state logic are removed from the final build.

When NOT to use

  • If your application state is primarily simple key-value pairs, `useState` and React Context might offer a more straightforward solution.
  • When your state management needs heavily rely on complex, built-in middleware patterns for asynchronous operations, consider solutions with more extensive plugin ecosystems.
  • If your team is already deeply invested in a different established state management pattern and the learning curve for a new, minimalist approach is not justified.
  • For projects that require a comprehensive, batteries-included solution for intricate global state management out-of-the-box.
  • When managing very complex, deeply nested states where a more opinionated hierarchical structure might simplify development and debugging.

nanostores Alternatives

nanostores Categories