Refactor .then()s to async functions

This commit is contained in:
Aarni Koskela
2019-10-24 18:28:21 +03:00
parent 543c1311ad
commit 7deb14d14a
3 changed files with 33 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ export default class InviteForm extends React.Component {
error: null,
};
onSubmit = e => {
onSubmit = async e => {
e.preventDefault();
this.setState({
@@ -21,12 +21,14 @@ export default class InviteForm extends React.Component {
error: null,
});
request
.post(api("invites"), {
try {
await request.post(api("invites"), {
email: this.state.email.trim(),
})
.then(this.handleSuccess)
.catch(this.handleError);
});
this.handleSuccess();
} catch (error) {
this.handleError(error);
}
};
handleSuccess = () => {