I am struggling to figure out issue with async await function, I keep getting error that said
await is a reserved word
I'm new at react and the async
function, I think the problem is where do I should put await
in this function properly?
handleSubmit = async (e) => {
try {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err && !this.state.added) {
this.setState({ submit: true });
await PopUpAdsService.create({
name: values.name,
photo: this.state.secureUrl,
type: values.type,
link: this.state.deepl,
status: values.status,
})
console.log(response);
if (response.data.status === 200) {
Notification(
'success',
'Pop-up has been created successfully',
);
this.setState({ submit: false, added: true });
setTimeout(() => {
this.props.history.replace('/dashboard/pop-up');
}, 2000);
}
} catch (error) {
console.log(error);
Notification(
'error',
`Oops! Error occured. ${error.response.data.message}`,
);
this.setState({ submit: false });
}
async handleSubmit(e) {
try {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err && !this.state.added) {
this.setState({ submit: true });
await PopUpAdsService.create({
name: values.name,
photo: this.state.secureUrl,
type: values.type,
link: this.state.deepl,
status: values.status,
})
console.log(response);
if (response.data.status === 200) {
Notification(
'success',
'Pop-up has been created successfully',
);
this.setState({ submit: false, added: true });
setTimeout(() => {
this.props.history.replace('/dashboard/pop-up');
}, 2000);
}
} catch (error) {
console.log(error);
Notification(
'error',
`Oops! Error occured. ${error.response.data.message}`,
);
this.setState({ submit: false });
}
}
});
};