Skip to content

Commit

Permalink
[Doc] Remove Input defaultValue syntax with a function
Browse files Browse the repository at this point in the history
Closes #5354
  • Loading branch information
fzaninotto committed Oct 12, 2020
1 parent 6897a5e commit 58a2c21
Showing 1 changed file with 2 additions and 3 deletions.
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

0 comments on commit 58a2c21

Please sign in to comment.