23 lines · 937 B · TypeScript
RawDownload
import { RegistryContext } from "@effect/atom-react";import {  type AtomCommand,  type AtomCommandOptions,  type AtomCommandResult,  runAtomCommand,} from "@t3tools/client-runtime/state/runtime";import { useCallback, useContext } from "react"; export function useAtomCommand<A, E, W>(  command: AtomCommand<W, A, E>,  options?: string | AtomCommandOptions,): (value: W) => Promise<AtomCommandResult<A, E>> {  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 useCallback(    (value: W) => runAtomCommand(registry, command, value, { label, reportFailure, reportDefect }),    [command, label, registry, reportDefect, reportFailure],  );}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t