Every component that subscribes to a NexusStore store must import two things: theDocumentation 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.
useStore hook and the store reference itself. In a small app that is manageable, but once you have a dozen components all reaching into authStore or themeStore, those repeated imports become noisy boilerplate. Custom hooks solve this by centralising the pairing of useStore + store in one place — components then import a single, clearly-named hook like useAuthStore and pass only their selector.
The Pattern in the Source
The demo app’ssrc/store/hooks.js shows the full pattern:
src/store/hooks.js
selector and forwards it straight to useStore alongside the bound store reference. The full useStore API is preserved: selectors work exactly as documented, stability recommendations still apply, and the return value is whatever the selector returns.
Using Custom Hooks in Components
Components import only the domain hook. There is no need to know which store backs the hook or where the store file lives.src/components/ThemeComponent.jsx
src/components/AuthComponent.jsx
ThemeComponent imports useThemeStore — it has no knowledge of themeStore being the backing store, or of useStore existing at all. If you later split themeStore into two stores or rename the store file, only hooks.js needs to change.
Creating a Custom Hook from Scratch
Create your store in store.js
Define your initial state and export the store. Wrap with
immer() if you need mutation-style updates.src/store/store.js
Create hooks.js in the same folder
Co-locate the hooks file next to the store so both live under
src/store/. This makes the domain boundary obvious at a glance.Export a named hook that wraps useStore
Import
useStore and the store reference, then re-export a function that accepts a selector and calls useStore with both.src/store/hooks.js
Exporting Action Helpers from the Same File
Custom hooks are not limited to read access. You can export named action functions from the samehooks.js file, keeping all store interaction — reads and writes — in a single module.
src/store/hooks.js — actions alongside hooks
Using a hook and action from the same module
Action helpers exported from
hooks.js are plain functions, not hooks — they can be called anywhere: event handlers, async functions, or other utilities. They do not need to follow the Rules of Hooks.Benefits at a Glance
Single import per domain
Components import one hook instead of both
useStore and the store reference. Less noise, fewer accidental imports of the wrong store.Easy to refactor
Renaming, splitting, or merging stores only touches
store.js and hooks.js. Component files do not need to change.Discoverable API
useAuthStore, useCartStore, useThemeStore — the hook name tells you exactly what domain it belongs to without reading the implementation.Co-located actions
Exporting action helpers from
hooks.js keeps all store interaction in one file, making the module the single source of truth for a domain.