logger
logger adds console groups around state updates. It is useful while shaping a store or debugging reducer actions.
Signature
logger<T>(initialState: T | Store<T>, options?: LoggerOptions): Store<T>
logger(options?: LoggerOptions): <T>(initialState: T | Store<T>) => Store<T>
type LoggerOptions = {
collapsed?: boolean;
diff?: boolean;
timestamp?: boolean;
};Example
import { logger } from '@ilokesto/state/middleware';
const store = logger({ count: 0 }, { collapsed: true, diff: true, timestamp: true });
store.setState((state) => ({ count: state.count + 1 }));What gets logged
- update title with the action name when reducer middleware supplied one,
- previous state,
- next state,
- optional timestamp,
- optional shallow-ish JSON diff for object keys.
Practical notes
logger is skipped when process.env.NODE_ENV === "production". The diff output is best-effort debugging information based on JSON serialization, not a formal patch. Use it to inspect flow, not to drive application logic.