ChimericAsyncFactory
Provided by @chimeric/react.
Creates an async operation usable both idiomatically (async/await) and reactively (.useHook() with manual invoke). Useful when dealing with promises and caching is not necessary.
import { ChimericAsyncFactory } from '@chimeric/react';
const fetchUser = ChimericAsyncFactory(async (params: { id: string }) => { const response = await fetch(`/api/users/${params.id}`); return response.json();});Idiomatic Path
Section titled “Idiomatic Path”const user = await fetchUser({ id: '123' });
// With retryconst user = await fetchUser({ id: '123' }, { options: { retry: 3 } });Reactive Path
Section titled “Reactive Path”The reactive path provides an invoke function. The operation does not auto-execute — you trigger it manually.
function UserProfile({ userId }: { userId: string }) { const { invoke, data, isPending, isError, error } = fetchUser.useHook();
return ( <div> <button onClick={() => invoke({ id: userId })}>Load User</button> {isPending && <div>Loading...</div>} {isError && <div>Error: {error?.message}</div>} {data && <div>{data.name}</div>} </div> );}Return value:
| Property | Type |
|---|---|
invoke | (params, options?) => Promise<TResult> |
data | TResult | undefined |
isPending | boolean |
isIdle | boolean |
isSuccess | boolean |
isError | boolean |
error | TError | null |
IdiomaticAsyncFactory and ReactiveAsyncFactory are also available for single-path usage.