From 58a2c219eb3f3e9c73d0f5fd495ef531af60ce3d Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Mon, 12 Oct 2020 18:57:12 +0200 Subject: [PATCH] [Doc] Remove Input defaultValue syntax with a function Closes #5354 --- docs/CreateEdit.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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