Skip to main content

StoreEffect

An object that describes a state change in a store. Zedux creates one of these every time a store's state changes. This is the object passed to effects subscribers and state machine listeners (on machines in the @zedux/machines package).

Definition

interface StoreEffect<State = any, S extends Store<State> = Store<State>> {
action: ActionChain
error?: unknown
newState: State
oldState?: State
store: S
}
action

A reference to the action (or ActionChain) object that triggered the state change or that caused the error.

Every state update in Zedux is triggered by an action. Even store.setState() and similar APIs always generate "psuedo actions" representing the change.

error

If the dispatch call errored, this will be a reference to the error that was thrown.

This only applies to errors thrown in reducers due to a call to store.dispatch(). If a function passed to store.setState() and similar methods throws an error, that error will be thrown back to the caller and subscribers won't be notified.

newState

The store's new state after passing the action through this store's reducer layer and to all child stores.

Effects subscribers run after the state has been completely updated, so this value will be exactly equal to store.getState().

oldState

The state of the store before this action changed it. Can be undefined if this is the first time this store's state has ever been set.

store

A reference to the store itself. Useful when external or general-purpose effects subscribers are registered without having a reference to the store they were registered in.

See Also