I am Working on a ReactJs project and I use formik in it.
I have 2 different components (parent and child).
Here is the example, I tried to pass the formik data from parent to child and I need to set parent formik values from child component.
Right now I face an error as my parent component call child and when the child updates parent value it will again call the child and goes in the infinite loop.
Parent.js
<GSTData gstData={this.props.gstDetails?.GstDetails}
amount={this.props.totalAmount}
onInputControlChange={(Total, GstData) => {
TotalBillAmount = Total;
GstDetails = GstData;
console.log('Total', TotalBillAmount)
//setFieldValue('NetOutStanding', 1);
}}
values={values}
setFieldValue={setFieldValue}
/>
Child.js
componentDidUpdate(){
this.props.onInputControlChange((this.GSTTotal + this.props.amount), this.GstDetails);
this.props.setFieldValue('NetOutStanding', (this.GSTTotal + this.props.amount));
}