Last active
April 22, 2020 22:42
-
-
Save rosschapman/9fec302abe53ff94faa4501231a137d9 to your computer and use it in GitHub Desktop.
Weakly Bound Form Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is oversimplified. The real code for this callback would be a complicated graph | |
// of nested asynchronous and synchronous calls. Imagine at the edge of thes thunks each | |
// dispatched action mutates state. | |
let postEntityForm = (e, data) => { | |
await dispatch(saveEntity(data)); | |
let entities = await dispatch(fetchEntities()); | |
let taxPolicy = await dispatch(maybeFetchEntityTaxPolicy()); | |
await dispatch(maybeUpdateEntityPriceSuggestions(taxPolicy, entities)); | |
let isEditing = dispatch(getIsEditingFromState()); | |
if (isEditing) { | |
dispatch(prePopulateForm(data)); | |
} else { | |
dispatch(resetForm()); | |
} | |
} | |
let MyFormComponent = () => { | |
return { | |
<Form> | |
<Button type={'submit'} onClick={postEntityForm}/> | |
</Form> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment