# useEntityPage

**Category:** Base Components/Pages/Entity Page/Hooks/useEntityPage

## API

### Overview

A React hook that creates the state for an [`EntityPage`](./?path=/story/base-components-pages-entity-page--entitypage). Configure entity fetching, save flow, form integration, toasts, and navigation. The returned [`EntityPageState`](./?path=/story/base-components-pages-entity-page-state--entitypagestate) is passed to ``.

```tsx
import { useEntityPage } from '@wix/patterns/page';
```

### Example

```tsx
import { useEntityPage, EntityPage } from '@wix/patterns/page';
import { useForm } from 'react-hook-form';

const form = useForm({ defaultValues: { name: '' } });

const state = useEntityPage({
  fetch: () => api.getItem(itemId).then((entity) => ({ entity })),
  onSave: ({ submittedValues }) =>
    api.updateItem(itemId, submittedValues).then((updatedEntity) => ({ updatedEntity })),
  form,
  container,
  parentPath: '/my-collection',
});

return (
  
    
    
      ...
    
  
);
```

### Returns

[EntityPageState](./?path=/story/base-components-pages-entity-page-state--entitypagestate)

### Props

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `fetch` | `() => Promise<{ entity: T \| undefined; }>` | Yes | - | A function that fetches the entity data. @returns a promise that resolves to an object containing the entity. |
| `onSave` | `(params: OnSaveParams) => Promise<{ updatedEntity: T; }>` | Yes | - | A function to handle the save action. @returns promise that resolves to an object that contains a 'updatedEntity' object. |
| `saveSuccessToast` | `string \| { message?: string; }` | No | - | An optional object with an optional message, or it can directly get a string message. |
| `saveErrorToast` | `((err: unknown, params: { retry: () => void; }) => string \| { message?: string; tryAgain?: boolean; action?: { text: string; onClick: () => void; } \| undefined; }) \| undefined` | No | - | An optional function to display an error toast message when a save operation fails. @returns An object with a `message` and an `action` object. Alternatively, it can return an object with an optional `message` and a `tryAgain` flag, or a string message. The previous return types are still supported but are now deprecated. |
| `parentPageId` | `string` | No | - | A string representing the ID of the parent page. Must be passed if not using Patterns Router |
| `parentPath` | `string` | No | - | A string representing the path of the parent page. Must be passed if using Patterns Router |
| `schemaSource` | `SchemaSource<T>` | No | - | An optional schema source describing how to load the schema and access the entity's data. When present, the page can read fields from the source instead of relying only on hand-wired fetch/onSave callbacks. |

