Skip to content

Instantly share code, notes, and snippets.

@bookercodes
Last active June 26, 2017 21:21
Show Gist options
  • Save bookercodes/94b2369787d60f157c18b166f4aab401 to your computer and use it in GitHub Desktop.
Save bookercodes/94b2369787d60f157c18b166f4aab401 to your computer and use it in GitHub Desktop.
import React from 'react'
import revalidation from 'revalidation'
const renderError = errors => {
if (errors && errors.length > 0) {
return <p>{errors[0]}</p>
}
}
const SimpleForm = ({
reValidation: { form, updateValue, errors = {}, validateAll },
onSubmit
}) =>
<form
onSubmit={e => {
e.preventDefault()
validateAll(onSubmit)
}}
>
<div>
<label>Name (<em>Required</em>):</label>
<input
type="text"
value={form.name}
onChange={e => updateValue('name', e.target.value)}
/>
{renderError(errors.name)}
</div>
<input type="submit" value="Submit" />
</form>
export default revalidation(SimpleForm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment