Commit d1beb62a authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH

fix small CacheInput bug (triggering unnecessary updates)

parent 63121e6f
......@@ -60,6 +60,7 @@ class CacheInput extends React.Component<Props, State>{
cache: this.props.value,
valid: false,
invalidityText: undefined,
// default of 500ms delay
msDelay: this.props.delay !== undefined ? this.props.delay : 500,
};
......@@ -103,14 +104,20 @@ class CacheInput extends React.Component<Props, State>{
change = (e: any) => {
this.clearTimer();
const newInput = e.target.value;
// no need to update the state if the value is the same
if(newInput === this.state.cache)
return;
const newValid = this.updateValidity(newInput);
this.setState({
cache: newInput,
});
// no need to update props if value is the same
if(newInput === this.props.value)
return;
if(newValid && this.props.onChange){
if(this.state.msDelay === 0)
if(this.state.msDelay === 0){
this.props.onChange(e);
else {
} else {
if(e.persist)
e.persist();
this.onChangeTimer = setTimeout(() => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment