arkynChangelogGuides
docs / hooks / use-automation

useAutomation

The useAutomation hook automates modal closing and toast notifications based on form response data.

Import

ts

import { useAutomation } from "@arkyn/components/useAutomation";
Learn how subpath and root imports differ in How do I use imports.
For the hook to work, you need to install the following dependencies:

bash

bun add react-scroll

Parameters

formResponseData (required)

Object containing automation metadata from a form response.
Type: any

Return value

The hook performs side effects and does not return a value.
Type: void

Usage example

tsx

import { useAutomation } from "@arkyn/components/useAutomation";
function SubmitFeedback({ responseData }: { responseData: any }) {
useAutomation(responseData);
return null;
}
// Example response data
const responseData = {
closeModal: true,
message: "Operation completed successfully!",
name: "Success",
};

Notes

  • If closeModal is truthy, the hook calls closeAll() from useModal().
  • If message is present, it decides toast style by matching name against badResponses and successResponses.
  • If cause.data.scrollTo is set, the hook smooth-scrolls to the named element using react-scroll.
  • If cause.fieldErrors is present, the first field error takes priority and is shown in the toast instead of message.
  • Requires context providers used by internal hooks: modal-provider and toast-provider.
  • Related hooks: useModal and useToast.
Related in Hooks
On this page
    arkyn