File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import {useDidUpdate} from 'hooks';
5
5
import { Validator } from './types' ;
6
6
import { InputProps } from './Input' ;
7
7
8
-
9
8
export interface FieldStateProps extends InputProps {
10
9
validateOnStart ?: boolean ;
11
10
validateOnChange ?: boolean ;
@@ -17,7 +16,7 @@ export interface FieldStateProps extends InputProps {
17
16
/**
18
17
* Callback for when field validity has changed
19
18
*/
20
- onChangeValidity ?: ( isValid : boolean ) => void
19
+ onChangeValidity ?: ( isValid : boolean ) => void ;
21
20
}
22
21
23
22
export default function useFieldState ( {
@@ -41,10 +40,16 @@ export default function useFieldState({
41
40
42
41
useEffect ( ( ) => {
43
42
if ( props . value !== value ) {
43
+
44
44
setValue ( props . value ) ;
45
+
46
+ if ( validateOnChange ) {
47
+ validateField ( props . value ) ;
48
+ }
45
49
}
46
- /* On purpose listen only to props.value change */
47
- } , [ props . value ] ) ;
50
+ /* On purpose listen only to props.value change */
51
+ /* eslint-disable-next-line react-hooks/exhaustive-deps*/
52
+ } , [ props . value , validateOnChange ] ) ;
48
53
49
54
useDidUpdate ( ( ) => {
50
55
onChangeValidity ?.( isValid ) ;
You can’t perform that action at this time.
0 commit comments