File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @cube-dev/ui-kit ' : minor
3+ ---
4+
5+ Apply form ` defaultValues ` change synchronously to avoid inconsistency.
Original file line number Diff line number Diff line change 55 forwardRef ,
66 ReactNode ,
77 useContext ,
8- useEffect ,
98 useRef ,
109} from 'react' ;
1110import { DOMRef } from '@react-types/shared' ;
@@ -117,6 +116,7 @@ function Form<T extends FieldTypes>(
117116 onSubmitFailed,
118117 ...otherProps
119118 } = props ;
119+ const defaultValuesRef = useRef ( defaultValues ) ;
120120 const firstRunRef = useRef ( true ) ;
121121 const isHorizontal = orientation === 'horizontal' ;
122122
@@ -224,11 +224,10 @@ function Form<T extends FieldTypes>(
224224 }
225225 }
226226
227- useEffect ( ( ) => {
228- if ( defaultValues ) {
229- form ?. setInitialFieldsValue ( defaultValues ) ;
230- }
231- } , [ defaultValues ] ) ;
227+ if ( defaultValuesRef . current !== defaultValues ) {
228+ form ?. setInitialFieldsValue ( defaultValues ?? { } ) ;
229+ defaultValuesRef . current = defaultValues ;
230+ }
232231
233232 return (
234233 < FormElement
You can’t perform that action at this time.
0 commit comments