Reputation: 37
I am passing a data from front end to back end using the below function
async componentDidMount(){
let data = this.state.i
const addFormData = await actions.addFormData(data).catch(e => console.log(e));
console.log("this is i for actions");
this.setState({rows: addFormData})
}
The entered form data is stored in the below function variable called
values
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
this.setState({
i:values
}, () => console.log(this.state.i))
}
});
}
I am getting this error
Can I know where is the mistake. Since I am new to this back end part of react
where passing api
Upvotes: 0
Views: 328
Reputation: 2106
you need to put it in a try catch block
try this:
async componentDidMount(){
let data = this.state.i;
try {
const addFormData = await actions.addFormData(data);
if(!addFormData ) return console.log("this is i for actions");
this.setState({rows: addFormData})
} catch(e) {
return console.log(e);
}
}
Upvotes: 2