Function registerStateChangedCallback

  • Registers a callback function that gets be invoked after the state changes.

    listenerId attribute should an unique identifier of the listener (the callback function).

    To be more specific, statePath gives some granularity to control which attribute change make the callback invoked.

    There are two possible values for statePath:

    • statePath is a single attribute callback listens to (so callback will be invoked only when this attribute changes),
    • statePath must be "*" (callback is invoked when any attribute changes). Please keep in mind in any of these cases, there changedPaths: string[] array of changed attributes array to check which attributes changed.

    The limitation is there is no possibility to listen to level-2 nested attributes. For example, if you have a state like so:

    export type Car = {
    engine: {
    horsepower: number;
    cylinders: number;
    };
    year: number;
    };

    there is no possibility to listen to horsepower attribute changes only (thus key-value-state-container name).

    IMPORTANT: each registerStateChangedCallback must be paired with unregisterStateChangedCallback call. Otherwise memory leaks occur.

    Type Parameters

    • TState extends Object

    • TAction extends Action

    Parameters

    Returns void

Generated using TypeDoc