@@ -31,14 +31,19 @@ class ValidatorComponent extends React.Component {
31
31
}
32
32
33
33
componentWillReceiveProps ( nextProps ) {
34
- if ( this . instantValidate ) {
34
+ if ( this . instantValidate && nextProps . value !== this . props . value ) {
35
35
this . validate ( nextProps . value ) ;
36
36
}
37
- if ( nextProps . validators && nextProps . errorMessages ) {
37
+ if ( nextProps . validators && nextProps . errorMessages &&
38
+ ( this . props . validators !== nextProps . validators || this . props . errorMessages !== nextProps . errorMessages ) ) {
38
39
this . setState ( { validators : nextProps . validators , errorMessages : nextProps . errorMessages } ) ;
39
40
}
40
41
}
41
42
43
+ shouldComponentUpdate ( nextProps , nextState ) {
44
+ return this . state !== nextState || this . props !== nextProps ;
45
+ }
46
+
42
47
componentWillUnmount ( ) {
43
48
this . context . form . detachFromForm ( this ) ;
44
49
}
@@ -85,7 +90,9 @@ class ValidatorComponent extends React.Component {
85
90
} ) ,
86
91
) ;
87
92
88
- this . setState ( { isValid : valid } ) ;
93
+ this . setState ( { isValid : valid } , ( ) => {
94
+ this . props . validatorListener ( this . state . isValid ) ;
95
+ } ) ;
89
96
}
90
97
91
98
@@ -110,11 +117,13 @@ ValidatorComponent.propTypes = {
110
117
validators : PropTypes . array ,
111
118
name : PropTypes . string ,
112
119
value : PropTypes . any ,
120
+ validatorListener : PropTypes . func ,
113
121
} ;
114
122
115
123
ValidatorComponent . defaultProps = {
116
124
errorMessages : 'error' ,
117
125
validators : [ ] ,
126
+ validatorListener : ( ) => { } ,
118
127
} ;
119
128
120
129
export default ValidatorComponent ;
0 commit comments