-
Notifications
You must be signed in to change notification settings - Fork 0
/
JobForm.js
49 lines (40 loc) · 1.13 KB
/
JobForm.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
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { useState } from 'react';
import axios from 'axios';
const JobForm = () => {
const [job, setJob] = useState({
title: '',
description: '',
location: '',
company: ''
});
const handleChange = (e) => {
setJob({
...job,
[e.target.name]: e.target.value
});
};
const handleSubmit = async (e) => {
e.preventDefault();
await axios.post('/api/jobs', job);
setJob({
title: '',
description: '',
location: '',
company: ''
});
};
return (
<form onSubmit={handleSubmit}>
<label>Title</label>
<input type="text" name="title" value={job.title} onChange={handleChange} />
<label>Description</label>
<input type="text" name="description" value={job.description} onChange={handleChange} />
<label>Location</label>
<input type="text" name="location" value={job.location} onChange={handleChange} />
<label>Company</label>
<input type="text" name="company" value={job.company} onChange={handleChange} />
<button type="submit">Create Job</button>
</form>
);
};
export default JobForm;