---
title: React Hooks
label: React Hooks
order: 70
desc: Make use of all of the powerful React hooks that Payload provides.
keywords: admin, components, custom, documentation, Content Management System, cms, headless, javascript, node, react, nextjs
---
Payload provides a variety of powerful [React Hooks](https://react.dev/reference/react-dom/hooks) that can be used within your own [Custom Components](./components), such as [Custom Fields](./fields). With them, you can interface with Payload itself to build just about any type of complex customization you can think of.
{path}
{ setValue(e.target.value) }} value={value} />fields,
},
{
value: "Deprecated. This property cannot be relied on as up-to-date.",
},
{
value: ''
}
],
[
{
value: submit,
},
{
value: "Method to trigger the form to submit",
},
{
value: ''
}
],
[
{
value: dispatchFields,
},
{
value: "Dispatch actions to the form field state",
},
{
value: ''
}
],
[
{
value: validateForm,
},
{
value: "Trigger a validation of the form state",
},
{
value: ''
}
],
[
{
value: createFormData,
},
{
value: <>Create a multipart/form-data object from the current form's state>,
},
{
value: ''
}
],
[
{
value: disabled,
},
{
value: "Boolean denoting whether or not the form is disabled",
},
{
value: ''
}
],
[
{
value: getFields,
},
{
value: 'Gets all fields from state',
},
{
value: '',
}
],
[
{
value: getField,
},
{
value: 'Gets a single field from state by path',
},
{
value: '',
},
],
[
{
value: getData,
},
{
value: 'Returns the data stored in the form',
},
{
value: '',
},
],
[
{
value: getSiblingData,
},
{
value: 'Returns form sibling data for the given field path',
},
{
value: '',
},
],
[
{
value: setModified,
},
{
value: <>Set the form\'s modified state>,
},
{
value: '',
},
],
[
{
value: setProcessing,
},
{
value: <>Set the form\'s processing state>,
},
{
value: '',
},
],
[
{
value: setSubmitted,
},
{
value: <>Set the form\'s submitted state>,
},
{
value: '',
},
],
[
{
value: formRef,
},
{
value: 'The ref from the form HTML element',
},
{
value: '',
},
],
[
{
value: reset,
},
{
value: 'Method to reset the form to its initial state',
},
{
value: '',
},
],
[
{
value: addFieldRow,
},
{
value: "Method to add a row on an array or block field",
},
{
drawerTitle: 'addFieldRow',
drawerDescription: 'A useful method to programmatically add a row to an array or block field.',
drawerSlug: 'addFieldRow',
drawerContent: (
<>
path,
},
{
value: "The path to the array or block field",
},
],
[
{
value: rowIndex,
},
{
value: "The index of the row to add. If omitted, the row will be added to the end of the array.",
},
],
[
{
value: data,
},
{
value: "The data to add to the row",
},
],
]}
/>
{' '}
{`import { useForm } from "payload/components/forms";
export const CustomArrayManager = () => {
const { addFieldRow } = useForm()
return (
)
}`}
An example config to go along with the Custom Component
{`const ExampleCollection = {
slug: "example-collection",
fields: [
{
name: "arrayField",
type: "array",
fields: [
{
name: "textField",
type: "text",
},
],
},
{
type: "ui",
name: "customArrayManager",
admin: {
components: {
Field: '/path/to/CustomArrayManagerField',
},
},
},
],
}`}
>
)
}
],
[
{
value: removeFieldRow,
},
{
value: "Method to remove a row from an array or block field",
},
{
drawerTitle: 'removeFieldRow',
drawerDescription: 'A useful method to programmatically remove a row from an array or block field.',
drawerSlug: 'removeFieldRow',
drawerContent: (
<>
path,
},
{
value: "The path to the array or block field",
},
],
[
{
value: rowIndex,
},
{
value: "The index of the row to remove",
},
],
]}
/>
{' '}
{`import { useForm } from "payload/components/forms";
export const CustomArrayManager = () => {
const { removeFieldRow } = useForm()
return (
)
}`}
An example config to go along with the Custom Component
{`const ExampleCollection = {
slug: "example-collection",
fields: [
{
name: "arrayField",
type: "array",
fields: [
{
name: "textField",
type: "text",
},
],
},
{
type: "ui",
name: "customArrayManager",
admin: {
components: {
Field: '/path/to/CustomArrayManagerField',
},
},
},
],
}`}
>
)
}
],
[
{
value: replaceFieldRow,
},
{
value: "Method to replace a row from an array or block field",
},
{
drawerTitle: 'replaceFieldRow',
drawerDescription: 'A useful method to programmatically replace a row from an array or block field.',
drawerSlug: 'replaceFieldRow',
drawerContent: (
<>
path,
},
{
value: "The path to the array or block field",
},
],
[
{
value: rowIndex,
},
{
value: "The index of the row to replace",
},
],
[
{
value: data,
},
{
value: "The data to replace within the row",
},
],
]}
/>
{' '}
{`import { useForm } from "payload/components/forms";
export const CustomArrayManager = () => {
const { replaceFieldRow } = useForm()
return (
)
}`}
An example config to go along with the Custom Component
{`const ExampleCollection = {
slug: "example-collection",
fields: [
{
name: "arrayField",
type: "array",
fields: [
{
name: "textField",
type: "text",
},
],
},
{
type: "ui",
name: "customArrayManager",
admin: {
components: {
Field: '/path/to/CustomArrayManagerField',
},
},
},
],
}`}
>
)
}
],
]}
/>
## useCollapsible
The `useCollapsible` hook allows you to control parent collapsibles:
| Property | Description |
| ------------------------- | ------------------------------------------------------------------------------------------------------------- |
| **`isCollapsed`** | State of the collapsible. `true` if open, `false` if collapsed. |
| **`isVisible`** | If nested, determine if the nearest collapsible is visible. `true` if no parent is closed, `false` otherwise. |
| **`toggle`** | Toggles the state of the nearest collapsible. |
| **`isWithinCollapsible`** | Determine when you are within another collapsible. |
**Example:**
```tsx
'use client'
import React from 'react'
import { useCollapsible } from '@payloadcms/ui'
const CustomComponent: React.FC = () => {
const { isCollapsed, toggle } = useCollapsible()
return (
I am {isCollapsed ? 'closed' : 'open'}