I am calling API on the onBlur/onChange of input field in Ant.Design(react redux based). on Calling API, It update the props of the component and on update of the props it call render method. in render method it re render the UI and call onBlur/onChange again and it got stuck in endless loop.
I have tried maintaining it in the state, but It is not stopping this recursive behavior.
render () {
const {
form: { getFieldDecorator, getFieldValue }, payload: { payload },
} = this.props;
console.log(" Client details " + JSON.stringify(this.props));
return ( <Form onSubmit={this.handleSubmit} hideRequiredMark style={{ marginTop: 8 }}>
<FormItem {...formItemLayout} label={<FormattedMessage id="form.seller.code" />}>
{getFieldDecorator('code', {
rules: [
{
required: true,
message: formatMessage({ id: 'validation.code.required' }),
},
],
})(<Input placeholder={formatMessage({ id: 'form.code.placeholder' })}
onChange={this.fetchDetails()}
/>)}
</FormItem>
</Form>
)
}
fetchDetails() {
const { dispatch, form } = this.props;
const value = this.props.form.getFieldValue('code');
dispatch({
type: 'form/fetchDetails',
payload: value,
});
}
expected result : just fetch the details once actual : repeated calls to onBlur and render method causing stuck in loop.
onChange={this.fetchDetails}instead ofonChange={this.fetchDetails()}