Skip to main content

Create Action

Parameters#

NameRequiredTypeDescription
SettingstrueSettingsAction settings object
createAction({  key: 'data',  name: 'ACTION_NAME',}) 

Settings#

name#

TypeDefaultRequiredDescription
String-YesThe action name.

key#

TypeDefaultRequiredDescription
String-NoThe name of the key in which the data will be stored

keys#

TypeDefaultRequiredDescription
String-NoStored data key when need find nested key

forceUpdate#

TypeDefaultRequiredDescription
Boolean-No----

persists#

TypeDefaultRequiredDescription
BooleanfalseNoStores data from store to localStorage on web and asyncStorage on mobile

apiCall#

TypeDefaultRequiredDescription
Function-NoThis is an API call function, that returns a Promise (required). If you want to update the store without a request to the server you can skip this property

merge#

createAction({  // ...other options  merge: (...args) => {    // your api call arguments goes here `args`         return // your logic here  } })
TypeDefaultRequiredDescription
Function-NoThis function return boolean and if it true after every call will be override existing data

reuducer#

If you need control reducer yourself you can use this method

Parameters#

NameRequiredTypeDescription
statetrueObjectState object
actiontrueActionAction object
createAction({  // ...other options  key: 'yourKey',  reducer: (state, action) => {    return {      ...state,      yourKey: {        ...state.yourKey,        ...action.data       }    }  } })

handleResponse#

If you need parse api call response manually. The return value of this function will be stored in store.

Parameters#

NameRequiredTypeDescription
datatrueanyApi call response
createAction({  // ...other options  handleResponse: (data) => {    // your code here    return //....  } })

onSuccess#

This function calls every time after a successful response

Parameters#

NameRequiredTypeDescription
datafalseEventArgumentsEvent arguments result and dispatch
createAction({  // ...other options  onSuccess: ({ result, dispatch }) => {    // ... do something here  } })

onError#

This function calls every time after a error response

Parameters#

NameRequiredTypeDescription
datafalseEventArgumentsEvent arguments result and dispatch
createAction({  // ...other options  onError: ({ result, dispatch }) => {    // ... do something here  } })

Methods#

restore#

Call action and restore your data and set default value

yourAction.restore()

delay#

Parameters#

NameRequiredTypeDescription
durationtruenumberDelay duration
yourAction.delay(1000)
// if you need call with other argumentsyourAction.delay(1000, arg1, arg2, /* ... */)

settings#

Parameters#

NameRequiredTypeDescription
-trueActionSettingsBefore call action you can change action settings
const updatedParamsAction = yourAction.settings({  // set any settings what you need})

updatedParamsAction()