Description Utility to create actions and control them by signals in a safe way.
It is not strictly necessary to use createAction to work with promises (e.g.
fetch), but it is recommended, since it allows you to control their
activation and monitoring.
Import import { createAction } from " dreamkit " ;
Definition declare const createAction : ( cb : ( ... args : any [] ) => any ) => {
readonly result : any | undefined ;
readonly running : boolean ;
readonly error : Error | undefined ;
readonly state : " idle " | " running " | " success " | " error " ;
Examples Basic usage import { $api, $route, createAction } from " dreamkit " ;
export const start = $api . title ( " Start " ) . create ( async () => {
await new Promise ( ( resolve ) => setTimeout (resolve , 1000 )) ;
if (id % 2 ) throw new Error ( " Random error " ) ;
const start = createAction (api . start );
< li > state : {start . state}</ li >
< li > result : {start . result}</ li >
< li > error : {start . error ?. message}</ li >
children = {api.start.title}
disabled = {!start.running}
Predefined params import { $api, $route, createAction, Input, s } from " dreamkit " ;
import { createEffect, createSignal } from " solid-js " ;
key: s . title ( " Key " ) . string (),
console . log ( " Received " , { key });
const [ key , setKey ] = createSignal ( "" );
const remove = createAction (api . remove ) . with ( () => ( { key: key () } ));
if (remove . state === " success " ) {
placeholder = {api.remove.params.key.options.title}
disabled = {remove.running}
children = {api.remove.title}