Skip to content

Create

The <Create> component is the main component for creation pages. It prepares a form submit handler, and renders the page title and actions. It is not responsible for rendering the actual form - that’s the job of its child component (usually a form component, like <SimpleForm>). This form component uses its children (<Input> components) to render each form input.

product creation form

The <Create> component creates a RecordContext with an empty object {} by default. It also creates a SaveContext containing a save callback, which calls dataProvider.create(), and a CreateContext containing both the record and the callback.

Wrap the <Create> component around the form you want to create, then pass it as create prop of a given <Resource>. <Create> requires no prop by default - it deduces the resource from the current URL.

For instance, the following component will render a creation form with 6 inputs when users browse to /products/create:

// in src/products.js
import {
Create,
SimpleForm,
TextInput,
ReferenceInput,
AutocompleteInput,
} from "@/components/admin";
import { required } from "ra-core";
export const ProductCreate = () => (
<Create>
<SimpleForm>
<TextInput source="reference" label="Reference" validate={required()} />
<ReferenceInput source="category_id" reference="categories">
<AutocompleteInput label="Category" validate={required()} />
</ReferenceInput>
<div className="grid grid-cols-2 gap-2">
<TextInput source="width" type="number" />
<TextInput source="height" type="number" />
</div>
<TextInput source="price" type="number" />
<TextInput source="stock" label="Stock" type="number" />
</SimpleForm>
</Create>
);
// in src/App.js
import { Admin } from '@/copmponents/admin';
import { Resource } from 'ra-core';
import { dataProvider } from './dataProvider';
import { PostCreate } from './posts';
const App = () => (
<Admin dataProvider={dataProvider}>
<Resource name="products" create={ProductCreate} />
</Admin>
);
export default App;

You can customize the <Create> component using the following props:

PropRequiredTypeDefaultDescription
childrenOptional *ReactNode-The components that render the form
renderOptional *function-Alternative to children. Function that renders the form, receives the create context as argument
actionsOptionalReactNodeDefault toolbarOverride the actions toolbar with a custom component
classNameOptionalstring-Passed to the root component
disableAuthenticationOptionalbooleanfalseDisable the authentication check
mutationModeOptionalstringpessimisticSwitch to optimistic or undoable mutations
mutationOptionsOptionalobject-Options for the dataProvider.create() call
recordOptionalobject{}Initialize the form with a record
redirectOptionalstring/function'edit'Change the redirect location after successful creation
resourceOptionalstringFrom URLOverride the name of the resource to create
titleOptionalstring/ReactNodeTranslationOverride the page title
transformOptionalfunction-Transform the form data before calling dataProvider.create()

* You must provide either children or render.