Skip to content

resetSubstore

Manages the full store reset lifecycle. A reset runs all registered callbacks in sequence, then executes a final afterReset callback (default: reload the page). Substores register their own reset logic via addResetCallback.

Table of contents

Properties

Methods


Properties

isResetting

isResetting: boolean

Whether a reset operation is currently running.

Set to true when reset is called and back to false once all callbacks complete (or fail). Use this to show a loading indicator or disable the reset button during the operation.

Related

  • reset — the operation that sets this flag

afterReset

afterReset: (
set: ImmerSet<GlobalStore>,
get: () => GlobalStore,
) => void | Promise<void>

Callback executed after all reset callbacks complete. Defaults to reloading the page.

Replace this with setAfterReset if you need custom post-reset behaviour (e.g., navigating to a different route instead of reloading).

Related


Methods

reset

reset: () => void

Triggers a full store reset by running all registered callbacks in sequence.

  1. Sets isResetting to true
  2. Runs each callback registered via addResetCallback in order (awaiting async callbacks)
  3. Runs afterReset
  4. Sets isResetting back to false

All SDK substores automatically register their own reset callbacks, so calling reset() clears the entire store state.

Related


addResetCallback

addResetCallback: (
callback: (
set: ImmerSet<GlobalStore>,
get: () => GlobalStore,
) => void | Promise<void>,
) => void

Registers a callback to be called during a reset operation.

Use this to hook into the reset lifecycle — for example, to clear your own application state alongside the SDK state. Callbacks are called in registration order. Async callbacks are awaited.

Parameters

NameTypeDescription
callbackResetCallbackFunction to run during reset. Receives Immer set and get for direct store mutation.

Related

  • reset — executes all registered callbacks

setAfterReset

setAfterReset: (
callback: (
set: ImmerSet<GlobalStore>,
get: () => GlobalStore,
) => void | Promise<void>,
) => void

Replaces the post-reset callback with a custom implementation.

Use this when you want to navigate to a specific route or perform an async operation after the reset instead of reloading the page.

Parameters

NameTypeDescription
callbackResetCallbackReplacement for the default page-reload callback

Related