NexusStore puts no limit on how many stores you create. Rather than fitting all your application state into a single monolithic object, you can — and usually should — split it into small, focused stores that each own a distinct domain. This keeps your code easy to reason about and means components only re-render when the state they actually use changes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iDevRanjan/nexus-store/llms.txt
Use this file to discover all available pages before exploring further.
When to use multiple stores
The clearest signal to reach for a separate store is that two pieces of state are independent — they have no shared actions, they are subscribed to by different components, and updating one never logically requires updating the other. Theme preference, authentication status, shopping cart contents, and user settings all fit this description. A good rule of thumb:Separate stores are completely isolated. Calling
setState on themeStore will never notify subscribers of authStore — even if a component happens to subscribe to both. Each store manages its own listener set entirely independently.A real-world example: store.js
The src/store/store.js file in the source repo shows two separate, focused stores alongside a larger combined store:
src/store/store.js
themeStore and authStore are small single-key stores — easy to test, easy to extend, and impossible to accidentally bloat. store groups several domains that belong to the same application context and may need to update together (see setMultiple below).
The golden rule: same action or separate action?
The most important question to ask when deciding whether to split state is: “Does a single user action need to update multiple fields at the same time?”| Scenario | Recommendation |
|---|---|
| One action updates two or more keys together | Keep them in the same store and use setMultiple |
| Two pieces of state change independently | Put them in separate stores |
| A component needs both pieces of state | That’s fine — subscribe to both stores separately |
Using setMultiple for co-ordinated updates
When fields within the same store change together, setMultiple lets you apply them atomically — subscribers are notified once, not once per field:
setMultiple — update several keys in one call
setMultiple merges the returned object into the existing state (shallow merge). Pass true as the second argument to replace the store entirely:
setMultiple with replace — replaces the entire store state
Cross-store updates
When you have two separate stores and a single user action should update both, callsetState on each store in sequence inside the same event handler:
Resetting auth and theme from one handler
Custom hooks per store
Exposing stores directly fromstore.js works, but a cleaner pattern is to wrap each store in a custom hook. The src/store/hooks.js file demonstrates this:
src/store/hooks.js
Organising stores at scale
One file per domain (recommended for large apps)
As your application grows, split stores into domain files and co-locate their hooks:
Single stores/ index file (recommended for medium apps)
Export everything from a single
src/store/store.js and src/store/hooks.js as shown in the source repo. Simple to navigate, easy to refactor.