createStore function creates a new store instance that holds atom state. Stores are independent of React and can be used outside of components or passed to a Provider.
Signature
Type Definitions
Parameters
No parameters.Returns
A store instance with three methods:
Examples
Basic Usage
Subscribe to Changes
With Provider
Outside React
Server-Side Rendering
Derived Atoms
Multiple Independent Stores
Integration with External Libraries
Notes
- Each store is completely independent - atoms in different stores don’t share state
- Stores can be used outside of React components
- The store holds weak references to atom state, allowing garbage collection when atoms are no longer used
- Store methods (
get,set,sub) are synchronous - The
submethod automatically mounts the atom and its dependencies - Calling
setwill trigger all subscribers of affected atoms - You typically don’t need to create stores manually -
Providercreates one automatically
Related APIs
- Provider - Provide a store to React components
- getDefaultStore - Get the default global store
- atom - Create atoms
- useAtom - Use atoms in React components