Function: useOptionalCommandExecutor()
ts
function useOptionalCommandExecutor(): OptionalCommandExecutor;Defined in: src/wirestate-react/commands/use-optional-command-executor.ts:32
Returns a stable function to dispatch optional commands on the active container.
Returns
An optional command executor function.
Remarks
Similar to useCommandExecutor, but returns null instead of throwing {WirestateError} if no handler is registered for the command type. Uses CommandBus.commandOptional internally.
Example
tsx
const executeOptionalCommand: OptionalCommandExecutor = useOptionalCommandExecutor();
const descriptor: CommandDescriptor<string> | null = executeOptionalCommand("OPTIONAL_COMMAND", data);
if (descriptor) {
const result: string = await descriptor.task;
}