Store Utilities API
Access and manipulate your global state outside of React components. Perfect for syncing state with storage, API headers, or performance optimization.
#initState(key, initialValue)
Initializes a global key at module scope, outside React components. Useful for service files, auth modules, and logging middleware.
#getState(key)
Synchronously retrieves the current value of a global key.
#setState(key, value | functional)
Updates the state of a global key from anywhere. Accepts a direct value or a functional update.
#batchUpdate(callback)
Bundles multiple updates into a single notification. Prevents multiple re-renders of the same component.
#resetState(key?)
Resets a specific key (or the entire store if no key provided) to its original initial value. Triggers notifications.
#destroyStore()
Completely clears the global registry and notifies all active listeners. Useful for testing or entire app teardown.
Memory Caution
resetState(key) or perform a complete teardown with destroyStore() when cleaning up large data structures to maintain peak performance.