Skip to content

Instantly share code, notes, and snippets.

@erikras
Created December 11, 2017 11:17
Show Gist options
  • Save erikras/f672c9bd3f01dad34b4a48afe7681b2b to your computer and use it in GitHub Desktop.
Save erikras/f672c9bd3f01dad34b4a48afe7681b2b to your computer and use it in GitHub Desktop.
A warning engine implemented in 🏁 React Final Form
const WarningEngine = ({ mutators: { setFieldData } }) => (
// FormSpy lets you listen to any part of the form state you want.
// If you provide an onChange prop, FormSpy will not render to the DOM.
<FormSpy
subscription={{ values: true }}
onChange={({ values }) => {
setFieldData('firstName', {
warning: values.firstName ? undefined : 'Recommended'
})
setFieldData('lastName', {
warning: values.lastName ? undefined : 'Recommended'
})
}}
/>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment