mobx-sentinel API doc
    Preparing search index...

    Type Alias Handlers

    type Handlers = {
        didSubmit: (succeed: boolean) => void;
        submit: (abortSignal: AbortSignal) => Promise<boolean>;
        willSubmit: (abortSignal: AbortSignal) => Promise<boolean>;
    }
    Index
    didSubmit: (succeed: boolean) => void

    Called once with the outcome after a submission finishes

    Use it for what follows the submission, e.g. showing a toast, closing a modal or drawer, syncing state that lives outside the form, logging, moving to the next UI state, or saving a snapshot.

    Not called for a submission cancelled by a newer one; the newer submission reports the outcome instead.

    It receives only the outcome. When the next step needs the submission's result (e.g. a created ID), have a submit handler store it where this handler can read it.

    Type Declaration

      • (succeed: boolean): void
      • Parameters

        • succeed: boolean

          true if submission succeeded, false if failed

        Returns void

    submit: (abortSignal: AbortSignal) => Promise<boolean>

    Async handler that performs the submission (serialized)

    The return value reports whether the submission succeeded, even when no async work is involved (e.g. false when the server rejects the data or a precondition does not hold). It becomes the outcome didSubmit handlers receive (true only if every submit handler returns true), and a form resets itself only when it is true.

    Cancellation does not depend on it: a submission cancelled by a newer one invokes no further handlers and resolves false whatever this returns. Pass abortSignal to async work (e.g. fetch) to cancel the work in flight, and keep fallback or cleanup for the request in this handler (try/catch/finally).

    Type Declaration

      • (abortSignal: AbortSignal): Promise<boolean>
      • Parameters

        • abortSignal: AbortSignal

          Abort signal for the submission, aborted when a newer submission cancels it

        Returns Promise<boolean>

        true if submission succeeded, false if failed (the remaining submit handlers are skipped)

    willSubmit: (abortSignal: AbortSignal) => Promise<boolean>

    Called before submission starts, to veto or prepare the submission (or to log it)

    Handlers run serially, in registration order.

    Type Declaration

      • (abortSignal: AbortSignal): Promise<boolean>
      • Parameters

        • abortSignal: AbortSignal

          Abort signal for the submission, aborted when a newer submission cancels it

        Returns Promise<boolean>

        true to continue submission, false to stop it (the submission fails and didSubmit receives false)