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 5
5
forwardRef ,
6
6
ReactNode ,
7
7
useContext ,
8
- useEffect ,
9
8
useRef ,
10
9
} from 'react' ;
11
10
import { DOMRef } from '@react-types/shared' ;
@@ -117,6 +116,7 @@ function Form<T extends FieldTypes>(
117
116
onSubmitFailed,
118
117
...otherProps
119
118
} = props ;
119
+ const defaultValuesRef = useRef ( defaultValues ) ;
120
120
const firstRunRef = useRef ( true ) ;
121
121
const isHorizontal = orientation === 'horizontal' ;
122
122
@@ -224,11 +224,10 @@ function Form<T extends FieldTypes>(
224
224
}
225
225
}
226
226
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
+ }
232
231
233
232
return (
234
233
< FormElement
You can’t perform that action at this time.
0 commit comments