Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Remove Input defaultValue syntax with a function #5387

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ To define default values, you can add a `initialValues` prop to form components
The value of the form `initialValues` prop is an object, or a function returning an object, specifying default values for the created record. For instance:

```jsx
const postDefaultValue = { created_at: new Date(), nb_views: 0 };
const postDefaultValue = () => ({ id: uuid(), created_at: new Date(), nb_views: 0 });
export const PostCreate = (props) => (
<Create {...props}>
<SimpleForm initialValues={postDefaultValue}>
Expand All @@ -1040,7 +1040,6 @@ Alternatively, you can specify a `defaultValue` prop directly in `<Input>` compo
export const PostCreate = (props) => (
<Create {...props}>
<SimpleForm>
<TextInput source="id" defaultValue={React.useMemo(() => uuid(), [])} disabled />
<TextInput source="title" />
<RichTextInput source="body" />
<NumberInput source="nb_views" defaultValue={0} />
Expand All @@ -1049,7 +1048,7 @@ export const PostCreate = (props) => (
);
```

**Tip**: For default values computed during the first render, or default values that are expensive to compute, use `React.useMemo` as in the example above.
**Tip**: Per-input default values cannot be functions. For default values computed at render time, set the `initialValues` at the form level, as explained in the previous section.

## Validation

Expand Down