-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make onSubmit/submitForm async #1229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,16 +445,17 @@ export class Formik<Values = FormikValues> extends React.Component< | |
this.setState({ isValidating: false }); | ||
const isValid = Object.keys(combinedErrors).length === 0; | ||
if (isValid) { | ||
this.executeSubmit(); | ||
return Promise.resolve(this.executeSubmit()); | ||
} else if (this.didMount) { | ||
// ^^^ Make sure Formik is still mounted before calling setState | ||
this.setState({ isSubmitting: false }); | ||
} | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this intentional to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree we should rather harmonize on a single return type like Promise<Result | null> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}); | ||
}; | ||
|
||
executeSubmit = () => { | ||
this.props.onSubmit(this.state.values, this.getFormikActions()); | ||
return this.props.onSubmit(this.state.values, this.getFormikActions()); | ||
}; | ||
|
||
handleBlur = (eventOrString: any): void | ((e: any) => void) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wrap this with
Promise.resolve
? Isn't the result the same without it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guarantees that a promise is returned. If
this.props.onSubmit
were to returnvoid
instead of a promise, this would ensure chaining.