Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

[FormState] Extend the return type of the submt handler. #736

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

mehdi-loup
Copy link
Contributor

The problem

In order to be able to return both void and RemoteError[] in an
async method, the 2 types needs to be lifted within a single Promise.
This PR extends the union of the SubmitHandler return type.

Example of use

In the render:

  <FormState onSubmit={this.handleSubmit} />

In the class:

private async handleSubmit() {
  const {data} = await mutation();
   if (error) { 
    return [{message: error.message}]
  }
  return;

Because handleSubmit being async, it would wrap all possible return type within one single promise, we need to the onSubmit prop of FormState to account for that too.

In order to be able to return both `void` and `RemoteError[]` in an
async method, the 2 types needs to be lifted within a single Promise.
This PR extends the union of the SubmitHandler return type.
@mehdi-loup mehdi-loup requested a review from marutypes June 4, 2019 17:19
@nimzco nimzco merged commit d81f1c4 into master Jun 4, 2019
@nimzco nimzco deleted the add-union-type-submit-handler-of-form-state branch June 4, 2019 20:02
mehdi-loup added a commit that referenced this pull request Jun 4, 2019
Changelog for #736
@mehdi-loup mehdi-loup mentioned this pull request Jun 4, 2019
@lemonmade lemonmade temporarily deployed to production June 5, 2019 15:41 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants