@@ -31,14 +31,19 @@ class ValidatorComponent extends React.Component {
3131 }
3232
3333 componentWillReceiveProps ( nextProps ) {
34- if ( this . instantValidate ) {
34+ if ( this . instantValidate && nextProps . value !== this . props . value ) {
3535 this . validate ( nextProps . value ) ;
3636 }
37- if ( nextProps . validators && nextProps . errorMessages ) {
37+ if ( nextProps . validators && nextProps . errorMessages &&
38+ ( this . props . validators !== nextProps . validators || this . props . errorMessages !== nextProps . errorMessages ) ) {
3839 this . setState ( { validators : nextProps . validators , errorMessages : nextProps . errorMessages } ) ;
3940 }
4041 }
4142
43+ shouldComponentUpdate ( nextProps , nextState ) {
44+ return this . state !== nextState || this . props !== nextProps ;
45+ }
46+
4247 componentWillUnmount ( ) {
4348 this . context . form . detachFromForm ( this ) ;
4449 }
@@ -85,7 +90,9 @@ class ValidatorComponent extends React.Component {
8590 } ) ,
8691 ) ;
8792
88- this . setState ( { isValid : valid } ) ;
93+ this . setState ( { isValid : valid } , ( ) => {
94+ this . props . validatorListener ( this . state . isValid ) ;
95+ } ) ;
8996 }
9097
9198
@@ -110,11 +117,13 @@ ValidatorComponent.propTypes = {
110117 validators : PropTypes . array ,
111118 name : PropTypes . string ,
112119 value : PropTypes . any ,
120+ validatorListener : PropTypes . func ,
113121} ;
114122
115123ValidatorComponent . defaultProps = {
116124 errorMessages : 'error' ,
117125 validators : [ ] ,
126+ validatorListener : ( ) => { } ,
118127} ;
119128
120129export default ValidatorComponent ;
0 commit comments