File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -112,11 +112,14 @@ function useField<FormValues: FormValuesShape>(
112112
113113 React . useEffect (
114114 ( ) =>
115- register ( ( state ) => {
115+ register ( ( newState ) => {
116116 if ( firstRender . current ) {
117117 firstRender . current = false ;
118+ if ( state . initial != newState . initial ) {
119+ setState ( newState ) ;
120+ }
118121 } else {
119- setState ( state ) ;
122+ setState ( newState ) ;
120123 }
121124 } , false ) ,
122125 // eslint-disable-next-line react-hooks/exhaustive-deps
Original file line number Diff line number Diff line change @@ -455,4 +455,27 @@ describe("useField", () => {
455455 expect ( spy . mock . calls [ 3 ] [ 1 ] ) . toBe ( spy . mock . calls [ 2 ] [ 1 ] ) ; // onFocus
456456 expect ( spy . mock . calls [ 3 ] [ 2 ] ) . toBe ( spy . mock . calls [ 2 ] [ 2 ] ) ; // onBlur
457457 } ) ;
458+
459+ it ( "should listen to initial value 2" , ( ) => {
460+ const MyFieldListener = ( ) => {
461+ const isFirstRender = React . useRef ( true )
462+ const { input, meta } = useField ( "name" ) ;
463+ if ( ! isFirstRender . current ) {
464+ expect ( meta . initial ) . toBe ( "test" ) ;
465+ // expect(input.value).toBe("test");
466+ }
467+ isFirstRender . current = false
468+ return null ;
469+ } ;
470+ render (
471+ < Form onSubmit = { onSubmitMock } >
472+ { ( ) => (
473+ < form >
474+ < MyFieldListener />
475+ < Field name = "name" component = "input" data-testid = "name" initialValue = "test" />
476+ </ form >
477+ ) }
478+ </ Form > ,
479+ ) ;
480+ } ) ;
458481} ) ;
You can’t perform that action at this time.
0 commit comments