This repository was archived by the owner on Aug 15, 2023. It is now read-only.
forked from ahandsel/React_Workshop_by_Kintone
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInputForm.js
More file actions
56 lines (47 loc) · 1.35 KB
/
InputForm.js
File metadata and controls
56 lines (47 loc) · 1.35 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// InputForm.js - Form component - Create a form that submits a POST request
// Import required files
import React, { useState } from 'react';
import getRecords from '../requests/getRecords.js';
import postRecord from '../requests/postRecord.js';
function InputForm(props) {
/* Create the component that submits a POST request */
// - - - - - - - START - - - - - - - -
const [title, setTitle] = useState('');
const [author, setAuthor] = useState('');
function buttonClick(title, author) {
postRecord(title, author)
.then(() => getRecords())
.then(result => props.setListItems(result))
}
function handleTitleChange(event) {
setTitle(event.target.value);
}
function handleAuthorChange(event) {
setAuthor(event.target.value);
}
return (
<div>
<form>
<div>
<label>Title: </label>
<input
type="text"
value={title}
onChange={handleTitleChange}
/>
</div>
<div>
<label>Author: </label>
<input
type="text"
value={author}
onChange={handleAuthorChange}
/>
</div>
<button type="button" onClick={() => buttonClick(title, author)}>Post to Kintone</button>
</form>
</div>
);
// - - - - - - - END - - - - - - - - -
};
export default InputForm;