Created
March 9, 2018 21:29
-
-
Save intojs/4a41a3817de53c9c8767d11d96d61d79 to your computer and use it in GitHub Desktop.
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
// @flow | |
import React from 'react'; | |
import type {FormData} from './ArticleFormContainer'; | |
type Props = { | |
formData: FormData; | |
changeArticleTitle: Function; | |
changeArticleAuthor: Function; | |
submitForm: Function; | |
} | |
export const ArticleFormComponent = (props: Props) => { | |
const { | |
formData, | |
changeArticleTitle, | |
changeArticleAuthor, | |
submitForm | |
} = props; | |
const onSubmit = (submitHandler) => (event) => { | |
event.preventDefault(); | |
submitHandler(event); | |
}; | |
return ( | |
<form | |
noValidate | |
onSubmit={onSubmit(submitForm)} | |
> | |
<div> | |
<label htmlFor="article-title">Title</label> | |
<input | |
type="text" | |
id="article-title" | |
name="articleTitle" | |
autoComplete="off" | |
value={formData.articleTitle.value} | |
onChange={changeArticleTitle} | |
/> | |
{!formData.articleTitle.valid && (<p>Please fill in the title</p>)} | |
</div> | |
<div> | |
<label htmlFor="article-author">Author</label> | |
<input | |
type="text" | |
id="article-author" | |
name="articleAuthor" | |
autoComplete="off" | |
value={formData.articleAuthor.value} | |
onChange={changeArticleAuthor} | |
/> | |
{!formData.articleAuthor.valid && (<p>Please fill in the author</p>)} | |
</div> | |
<button | |
type="submit" | |
value="Submit" | |
> | |
Create article | |
</button> | |
</form> | |
) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment