formik-observer
formik-observer copied to clipboard
Compare old value and new value instead
I think we can do something like this to prevent calling of onChange multiple times.. Let me know your thoughts
import React from 'react';
import { debounce, isEqual } from 'lodash';
class FormObserver extends React.Component {
state = {
currentFormValues: undefined
}
onChange = debounce((data, options) => this.props.onChange(data, options), 250)
componentWillReceiveProps(props) {
const { onChange, values, ...options } = props;
if (!isEqual(values, this.state.currentFormValues)) {
this.state.currentFormValues = values;
this.onChange(values, options)
}
}
render() {
return null
}
}
export default FormObserver;