useEffectAction function

Module @runic-artifex/views-effect/react in @runic-artifex/views-effect 0.23.0

function useEffectAction<Args extends readonly unknown[], A, E, R = never>(program: (...args: Args) => Effect.Effect<A, E, R>, ...[options]: [
    R
] extends [
    never
] ? [
    options?: EffectActionOptions<A, E, R>
] : [
    options: EffectActionOptions<A, E, R> & {
        readonly runFork: (effect: Effect.Effect<A, E, R>) => Fiber.Fiber<A, E>;
    }
]): EffectActionHandle<Args, A, E>;

Runs an Effect workflow from a component and renders its status, value and typed error. A new run interrupts the previous one, and unmounting interrupts the current run, which cancels an interrupted operation in .NET.

const save = useEffectAction(() => operation(() => client!.startSave(), { timeout: "10 seconds" }));
<button disabled={!client || save.pending} onClick={() => void save.run()}>Save</button>
{save.error?._tag === "ViewOperationTimedOut" && <p role="alert">Saving took too long.</p>}

The latest program and runFork are used when run is called, so they may close over the latest props.