Last active
June 26, 2017 21:21
-
-
Save bookercodes/94b2369787d60f157c18b166f4aab401 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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