import { RegistryContext } from "@effect/atom-react"; import { type AtomCommand, type AtomCommandOptions, type AtomCommandResult, runAtomCommand, } from "@t3tools/client-runtime/state/runtime"; import { useContext } from "react"; export function useAtomCommand( command: AtomCommand, options?: string | AtomCommandOptions, ): (value: W) => Promise> { const registry = useContext(RegistryContext); const label = typeof options === "string" ? options : (options?.label ?? command.label); const reportFailure = typeof options === "string" ? true : (options?.reportFailure ?? true); const reportDefect = typeof options === "string" ? true : (options?.reportDefect ?? true); return (value: W) => runAtomCommand(registry, command, value, { label, reportFailure, reportDefect }); }