# useTrixtaAction

{% code overflow="wrap" %}

```tsx
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)=>{}
   });
```

{% endcode %}

### Options

* `roleName : string`
  * **Required**
  * Trixta role name

* `actionName : string`
  * **Required**
  * Trixta action name

* `actionParameters: see related` [submitTrixtaActionResponse](https://trixtateam.gitbook.io/trixta-js-core/reference/methods/actions/submittrixtaactionresponse) `parameters`

* `loadingStatusRef: string`

  * Optional
  * 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: boolean`
    * Optional
    * Defaults to false.
    * If set to `true`, enables Trixta console debugging
  * `autoSubmit: boolean`
    * Optional
    * Defaults to false.
    * If set to `true`, hook will submit `actionParameters` to `actionName` when the component mounts.
  * `setTimeoutEventAsErrorEvent: boolean`
    * Optional
    * Defaults to false.
    * If set to `true`, will set the `actionParameters` `timeoutEvent` to be the same as the `errorEvent`
  * `clearResponsesOnCallback: boolean`

    * Optional
    * Defaults to false.
    * If set to `true`, will clear all responses when `onSuccess` or `onError` callbacks are called returning a value true.

* `onSuccess : (success: TSuccessType) => void|boolean`

  * Optional
  * This function will fire any time a successful response is received from Trixta.
  * If you return `true` and clearResponsesOnCallback is `true`, all responses will be cleared.

* `onError : (error: TErrorType) => void|boolean`
  * Optional
  * This function will fire any time an error response is received from Trixta.
  * If you return `true` and clearResponsesOnCallback is `true`, all responses will be cleared.

### Returns

* `hasRoleAccess : boolean`

  * Will be `true` if the `roleName` has access for this user.

* `isInProgress : boolean`

  * Will be `true` if there is no response yet after calling [`submitTrixtaActionResponse`](https://trixtateam.gitbook.io/trixta-js-core/reference/methods/actions/submittrixtaactionresponse) or `submitTrixtaAction`.
  * Will be `false` if there is a response after calling [`submitTrixtaActionResponse`](https://trixtateam.gitbook.io/trixta-js-core/reference/methods/actions/submittrixtaactionresponse) or `submitTrixtaAction`

* `hasResponse : boolean`

  * Will be `true` if there is at least one Trixta Instance response.

* `loading : boolean`

  * Will be `true` if the action is waiting to be loaded.

* `response :` [`TrixtaInstanceResponse`](https://trixtateam.gitbook.io/trixta-js-core/reference/types/action-related-types)

  * First or most recent Trixta instance response

* `latestInstance : TrixtaInstance`

  * First or most recent Trixta instance

* `submitTrixtaAction : (parameters:` [`SubmitTrixtaFunctionParameters`](https://trixtateam.gitbook.io/trixta-js-core/reference/methods/actions/submittrixtaactionresponse)`) => void`

  * This function will submit a request for the given `roleName` and `actionName`

  &#x20;

* `clearActionResponses : () => void`
  * This function will clear and reset responses for the given `roleName` and `actionName`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trixtateam.gitbook.io/trixta-js-core/reference/hooks/actions/usetrixtaaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
