useActionField
Returns a callback that executes the action selected in an
action field.
See In-depth: Actions.
function useActionField(props: {field: string}): () => Promise<unknown> | undefined
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
Returns
A callback that executes the selected action with the settings the user configured. The callback does nothing and
returns undefined while the dashboard is edited in the dashboard builder, or if no action is selected.
Example
src/widgets/example/Example.tsx
import React from 'react'
import {useActionField, useRipple} from '@modbros/dashboard-sdk'
export default function Example() {
const execute = useActionField({field: 'action'})
const ripple = useRipple()
return (
<button
style={{width: '100%', height: '100%'}}
onClick={(event) => {
ripple(event.clientX, event.clientY)
execute()
}}
>
Run action
</button>
)
}