-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateUser.jsx
58 lines (50 loc) · 1.64 KB
/
CreateUser.jsx
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
57
58
import React, { Component } from 'react';
import axios from "axios";
class CreateUser extends Component {
constructor(props){
super();
this.state = {
username: ""
}
this.onChangeUsername = this.onChangeUsername.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
onChangeUsername(e) {
this.setState({ username: e.target.value})
}
onSubmit(e) {
e.preventDefault();
const user = {
username: this.state.username,
}
console.log(user);
axios.post('http://localhost:5000/users/add', user)
// .then(res => console.log(res.data));
.then(res => alert(res.data));
this.setState({
username: ''
})
}
render() {
return (
<div className="container">
<h3>Create New User</h3>
<form onSubmit={this.onSubmit}>
<div className="form-group">
<label>Username: </label>
<input
type="text" required
className="form-control"
value={this.state.username}
onChange={this.onChangeUsername}
/>
</div>
<div className="form-group">
<input type="submit" value="Create User" className="btn btn-primary" />
</div>
</form>
</div>
);
}
}
export default CreateUser;