useTrixtaReaction
React hook used to interact with a Trixta reaction for a given roleName.
import { useTrixtaReaction } from '@trixtateam/trixta-js-core';
const {
hasRoleAccess,
isInProgress,
latestResponse,
loading,
latestInstance,
instances,
initialData,
hasResponse,
submitTrixtaReaction,
clearReactionResponses,
} = useTrixtaReaction<TInitialData,TSuccessType,TErrorType>({ roleName:"",
reactionName:"",
requestForEffect:false,
loadingStatusRef:"",
debugMode: false,
setTimeoutEventAsErrorEvent: false,
clearResponsesOnCallback: false,
onSuccess:(success)=>{},
onError:(errror)=>{}
});Options
roleName : stringRequired
Trixta role name
reactionName : stringRequired
Trixta reaction name
requestForEffect: booleanOptional
Defaults to false.
If set to
true, this Trixta reaction is not waiting for a response and the only expect to use the initialData
loadingStatusRef: stringOptional
Optional value to change the default isInProgress behaviour for when submitting reactions. If you plan to use the same reaction name for the same role, on the same screen, this is when you would make use of this * property
debugMode: booleanOptional
Defaults to false.
If set to
true, enables Trixta console debugging
setTimeoutEventAsErrorEvent: booleanOptional
Defaults to false.
If set to
true, will set thetimeoutEventto 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 callingsubmitTrixtaReactionResponseorsubmitTrixtaReaction.Will be
falseif there is a response after callingsubmitTrixtaReactionResponseorsubmitTrixtaReaction
hasResponse : booleanWill be
trueif there is at least one Trixta Instance response.
loading : booleanWill be
trueif the reaction is waiting to be loaded or receive a reaction.
latestResponse :TrixtaReactionInstanceResponseFirst or most recent Trixta instance response
initialData : TInitialData onTrixtaReactionInstanceInitial data returned from Trixta reaction instance
latestInstance :TrixtaReactionInstanceFirst or most recent Trixta instance
submitTrixtaReaction : (parameters:SubmitTrixtaFunctionParameters) => voidThis function will submit a response for the given
roleNameandreactionName
clearReactionResponses : () => voidThis function will clear and reset responses for the given
roleNameandreactionName.
Last updated
Was this helpful?