forked from kentcdodds/react-testing-library-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-editor-03-api.js
36 lines (31 loc) · 912 Bytes
/
post-editor-03-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react'
import {savePost} from './api'
function Editor({user}) {
const [isSaving, setIsSaving] = React.useState(false)
function handleSubmit(e) {
e.preventDefault()
const {title, content, tags} = e.target.elements
const newPost = {
title: title.value,
content: content.value,
tags: tags.value.split(',').map(t => t.trim()),
authorId: user.id,
}
setIsSaving(true)
savePost(newPost)
}
return (
<form onSubmit={handleSubmit}>
<label htmlFor="title-input">Title</label>
<input id="title-input" name="title" />
<label htmlFor="content-input">Content</label>
<textarea id="content-input" name="content" />
<label htmlFor="tags-input">Tags</label>
<input id="tags-input" name="tags" />
<button type="submit" disabled={isSaving}>
Submit
</button>
</form>
)
}
export {Editor}