diff --git a/docs/CreateEdit.md b/docs/CreateEdit.md index 395e7664211..07796afa180 100644 --- a/docs/CreateEdit.md +++ b/docs/CreateEdit.md @@ -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) => ( @@ -1040,7 +1040,6 @@ Alternatively, you can specify a `defaultValue` prop directly in `` compo export const PostCreate = (props) => ( - uuid(), [])} disabled /> @@ -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