# Building frontends  ## Reading data from models  Gadget provides the [`@gadgetinc/react`](https://npmjs.com/package/@gadgetinc/react) library of React hooks for reading and writing data from your Gadget models. The `useFindOne`, `useFindMany`, `useFindBy`, and `useGet` hooks read data from your backend models and render UI with React. Each of these hooks returns an object with the requested `data`, the `fetching` state, and an `error` if one was encountered, as well as a `refetch` function for refreshing the data if need be. For example, if you have a model named `post`, we can fetch post records in a variety of ways: ```tsx // fetch one post by id const [{ data, fetching, error }, refetch] = useFindOne(api.post, "10"); // fetch the first 10 posts const [{ data, fetching, error }, refetch] = useFindMany(api.post, { first: 10 }); // fetch the first post with the slug field equal to "example-slug", throw if it isn't found const [{ data, fetching, error }, refetch] = useFindFirst(api.post, { where: { slug: "example-slug" } }); // fetch the first post with the slug field equal to "example-slug", return null if it isn't found const [{ data, fetching, error }, refetch] = useMaybeFindFirst(api.post, { where: { slug: "example-slug" } }); // fetch a realtime-updated view of the first 10 posts from the backend const [{ data, fetching, error }, refetch] = useFindMany(api.post, { live: true, first: 10 }); // fetch the user's current session const [{ data, fetching, error }, refetch] = useGet(api.currentSession); ``` Each of these hooks must be wrapped in a React component to render. For example, we can use `useFindMany` to display a list of posts in a component: ```tsx import { useFindMany } from "@gadgetinc/react"; import { ReactNode } from "react"; import { api } from "../api"; export const PostsList = () => { const [{ data, fetching, error }, _refetch] = useFindMany(api.post, { first: 10 }); if (fetching) { return
Loading...
; } if (error) { return
Error: {error.message}
; } return ( ); }; ``` For more documentation on the `@gadgetinc/react` hooks library, see the [React reference](https://docs.gadget.dev/reference/react). ## Writing data to models  The [`@gadgetinc/react`](https://npmjs.com/package/@gadgetinc/react) React hooks library includes the [`useActionForm` hook](https://docs.gadget.dev/guides/frontend/forms) and the [`useAction` hook](https://docs.gadget.dev/reference/react#useaction) for writing data to models by running [Actions](https://docs.gadget.dev/guides/actions). `useActionForm` is suitable for building forms that give users inputs to control the input data, and `useAction` is a lower level hook for calling actions directly. ### Building forms  With the `useActionForm` hook, you can manage form state and call actions easily. For example, we can build a form for a `post` model with `useActionForm`: ```tsx import { useActionForm } from "@gadgetinc/react"; import { api } from "../api"; const PostForm = () => { const { register, submit } = useActionForm(api.post.create); return (