# Frontend forms  Gadget provides helpers for quickly building great frontend form experiences. ## AutoForm autocomponents  Gadget will generate forms for you automatically that are pre-hooked up to call your app's API. Forms are customizable and use an underlying design system to ensure a consistent look and feel. This is the fastest way to get started with forms in Gadget. The following will auto-generate a form for creating a new `post` and will include inputs for each field on the `post` model: ```tsx import { AutoForm } from "@gadgetinc/react/auto/polaris"; import { api } from "../api"; const PostForm = () => { const { register, submit } = useActionForm(api.post.create); return ; }; ``` See the [autocomponents guide](https://docs.gadget.dev/guides/frontend/autocomponents) for more info. ## `useActionForm` hook  The [`useActionForm`](https://docs.gadget.dev/reference/react#useActionForm) hook is the main hook for building forms with Gadget. It manages: * retrieving initial form data * getting and setting form values as users interact with a form * submitting the form by calling an [action](https://docs.gadget.dev/guides/actions) in your app's backend * displaying validation errors from the backend if they occur `useActionForm` supports calling actions on [models](https://docs.gadget.dev/guides/models) as well as [global actions](https://docs.gadget.dev/guides/actions). ### Setting up a form  To set up a form, call the `useActionForm` helper with the action you want to run when the form is submitted. The `useActionForm` hook returns two main functions for form building: * a `register` function that returns props for each form field * and a `submit` function for calling to run the action For example, if you have a backend model called `post` and an action called `create` on `post`, you can make a form for calling that action: ```tsx import { useActionForm } from "@gadgetinc/react"; import { api } from "../api"; const PostForm = () => { const { register, submit } = useActionForm(api.post.create); return (
); }; ``` #### No-input forms  Certain forms do not incorporate input elements; instead, they trigger backend logic when users click on them. For instance, a button that triggers a data sync may not require any user input but still needs to trigger an action. In cases where there is no need to manage form state, opting for `useAction` over `useActionForm` is often a more straightforward approach to handle these elements. For example, if we have a `post` model that has a `publish` action, we can build a button to trigger this mutation with the `useAction` hook: ```tsx import { useAction } from "@gadgetinc/react"; import { api } from "../api"; export const PostPublishButton = (props: { post: { id: string } }) => { const [{ data, fetching, error }, act] = useAction(api.post.publish); return ( ); }; ``` ### Other popular libraries  The React ecosystem has several other approaches to form building which can be used with Gadget. Popular libraries like [`formik`](https://formik.org/) or plain state management with `useState` and `useReducer` in React can be used to build forms with Gadget as well.