useTrixtaAction
React hook used to interact with a Trixta action for a given roleName.
import { useTrixtaAction } from '@trixtateam/trixta-js-core';
const {
hasRoleAccess,
isInProgress,
hasResponse,
loading,
latestInstance,
response,
submitTrixtaAction,
clearActionResponses,
} = useTrixtaAction<TSuccessType,TErrorType>({ roleName:"",
actionName:"",
actionParameters:{
data:{},
extraData:{},
timeout:1500,
timeoutEvent:"",
loadingStatusRef:"",
requestEvent:"",
responseEvent:"",
errorEvent:""
},
loadingStatusRef:"",
options: {
debugMode: false,
autoSubmit: false,
setTimeoutEventAsErrorEvent: false,
clearResponsesOnCallback: false,
},
onSuccess:(success)=>{},
onError:(errror)=>{}
});Options
roleName : stringRequired
Trixta role name
actionName : stringRequired
Trixta action name
actionParameters: see relatedsubmitTrixtaActionResponseparametersloadingStatusRef: stringOptional
Optional value to change the default isInProgress behaviour for when submitting actions. If you plan to use the same action name for the same role, on the same screen, this is when you would make use of this * property
options: { debugMode, autoSubmit, setTimeoutEventAsErrorEvent, clearResponsesOnCallback }debugMode: booleanOptional
Defaults to false.
If set to
true, enables Trixta console debugging
autoSubmit: booleanOptional
Defaults to false.
If set to
true, hook will submitactionParameterstoactionNamewhen the component mounts.
setTimeoutEventAsErrorEvent: booleanOptional
Defaults to false.
If set to
true, will set theactionParameterstimeoutEventto be the same as theerrorEvent
clearResponsesOnCallback: booleanOptional
Defaults to false.
If set to
true, will clear all responses whenonSuccessoronErrorcallbacks are called returning a value true.
onSuccess : (success: TSuccessType) => void|booleanOptional
This function will fire any time a successful response is received from Trixta.
If you return
trueand clearResponsesOnCallback istrue, all responses will be cleared.
onError : (error: TErrorType) => void|booleanOptional
This function will fire any time an error response is received from Trixta.
If you return
trueand clearResponsesOnCallback istrue, all responses will be cleared.
Returns
hasRoleAccess : booleanWill be
trueif theroleNamehas access for this user.
isInProgress : booleanWill be
trueif there is no response yet after callingsubmitTrixtaActionResponseorsubmitTrixtaAction.Will be
falseif there is a response after callingsubmitTrixtaActionResponseorsubmitTrixtaAction
hasResponse : booleanWill be
trueif there is at least one Trixta Instance response.
loading : booleanWill be
trueif the action is waiting to be loaded.
response :TrixtaInstanceResponseFirst or most recent Trixta instance response
latestInstance : TrixtaInstanceFirst or most recent Trixta instance
submitTrixtaAction : (parameters:SubmitTrixtaFunctionParameters) => voidThis function will submit a request for the given
roleNameandactionName
clearActionResponses : () => voidThis function will clear and reset responses for the given
roleNameandactionName.
Last updated
Was this helpful?