You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`children`| Optional *|`ReactNode`| - | The components that render the form |
61
+
|`render`| Optional *|`function`| - | Alternative to children. Function that renders the form, receives the create context as argument |
62
+
|`actions`| Optional |`ReactNode`| Default toolbar| Override the actions toolbar with a custom component |
63
+
|`aside`| Optional |`ReactNode`| - | Component to render aside to the main content |
64
+
|`className`| Optional |`string`| - | Passed to the root component |
65
+
|`component`| Optional |`string`/`Component`|`Card`| Override the root component |
66
+
|`disableAuthentication`| Optional |`boolean`|`false`| Disable the authentication check |
67
+
|`mutationMode`| Optional |`string`|`pessimistic`| Switch to optimistic or undoable mutations |
68
+
|`mutationOptions`| Optional |`object`| - | Options for the `dataProvider.create()` call |
69
+
|`record`| Optional |`object`|`{}`| Initialize the form with a record |
70
+
|`redirect`| Optional |`string`/`function`|`'edit'`| Change the redirect location after successful creation |
71
+
|`resource`| Optional |`string`| From URL | Override the name of the resource to create |
72
+
|`sx`| Optional |`object`| - | Override the styles |
73
+
|`title`| Optional |`string`/`ReactNode`| Translation | Override the page title |
74
+
|`transform`| Optional |`function`| - | Transform the form data before calling `dataProvider.create()`|
75
+
76
+
`*` You must provide either `children` or `render`.
72
77
73
78
## `actions`
74
79
@@ -120,6 +125,28 @@ const PostCreate = () => (
120
125
121
126
{% endraw %}
122
127
128
+
## `children`
129
+
130
+
The `<Create>` component will render its children inside a [`CreateContext`](./useCreateContext.md#return-value). Children can be any React node, but are usually a form component like [`<SimpleForm>`](./SimpleForm.md), [`<TabbedForm>`](./TabbedForm.md), or the headless [`<Form>`](./Form.md) component.
**Tip**: Alternatively to `children`, you can pass a [`render`](#render) prop to `<Create>`.
149
+
123
150
## `component`
124
151
125
152
By default, the `<Create>` view render the main form inside a Material UI `<Card>` element. The actual layout of the form depends on the `Form` component you're using ([`<SimpleForm>`](./SimpleForm.md), [`<TabbedForm>`](./TabbedForm.md), or a custom form component).
@@ -160,9 +187,9 @@ const PostCreate = () => (
160
187
161
188
The `<Create>` view exposes a Save button, which perform a "mutation" (i.e. it creates the data). React-admin offers three modes for mutations. The mode determines when the side effects (redirection, notifications, etc.) are executed:
162
189
163
-
-`pessimistic` (default): The mutation is passed to the dataProvider first. When the dataProvider returns successfully, the mutation is applied locally, and the side effects are executed.
164
-
-`optimistic`: The mutation is applied locally and the side effects are executed immediately. Then the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
165
-
-`undoable`: The mutation is applied locally and the side effects are executed immediately. Then a notification is shown with an undo button. If the user clicks on undo, the mutation is never sent to the dataProvider, and the page is refreshed. Otherwise, after a 5 seconds delay, the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
190
+
*`pessimistic` (default): The mutation is passed to the dataProvider first. When the dataProvider returns successfully, the mutation is applied locally, and the side effects are executed.
191
+
*`optimistic`: The mutation is applied locally and the side effects are executed immediately. Then the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
192
+
*`undoable`: The mutation is applied locally and the side effects are executed immediately. Then a notification is shown with an undo button. If the user clicks on undo, the mutation is never sent to the dataProvider, and the page is refreshed. Otherwise, after a 5 seconds delay, the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
166
193
167
194
By default, pages using `<Create>` use the `pessimistic` mutation mode as the new record identifier is often generated on the backend. However, should you decide to generate this identifier client side, you can change the `mutationMode` to either `optimistic` or `undoable`:
168
195
@@ -315,6 +342,37 @@ Note that the `redirect` prop is ignored if you set [the `mutationOptions` prop]
315
342
316
343
If you want to allow the user to enter several records one after the other, setting `redirect` to `false` won't make it, as the form isn't emptied by default. You'll have to empty the form using the `mutationOptions`, and this option disables the `redirect` prop. Check [the Save And Add Another section](#save-and-add-another) for more details.
317
344
345
+
## `render`
346
+
347
+
Alternatively to `children`, you can pass a `render` prop to `<Create>`. It will receive the [`CreateContext`](./useCreateContext.md#return-value) as its argument, and should return a React node.
348
+
349
+
This allows to inline the render logic for the create page.
**Tip**: When receiving a `render` prop, the `<Create>` component will ignore the `children` prop.
375
+
318
376
## `resource`
319
377
320
378
Components based on `<Create>` are often used as `<Resource create>` props, and therefore rendered when the URL matches `/[resource]/create`. The `<Create>` component generates a call to `dataProvider.create()` using the resource name from the URL by default.
0 commit comments