Overview
ThegetState method returns the current state of the store. It provides immediate, synchronous access to all state values including computed properties.
Signature
Return Value
The current state object containing all state values and computed properties.
- Returns a direct reference to the state object
- Includes computed values (getters) evaluated at call time
- Always reflects the latest state after any updates
Basic Example
Accessing After Updates
With Computed Values
In Custom Actions
UsegetState in custom actions to read current values:
Reading in Effects
Access state within effect callbacks:Direct Reference
getState() returns a direct reference to the state object. Modifying it directly will not trigger updates:
Type Safety
TypeScript provides complete type information:Use Cases
Reading for External APIs
Logging and Debugging
See Also
- createStore - Create a vanilla store
- effect - Subscribe to state changes
- batchUpdates - Batch multiple updates