-
Notifications
You must be signed in to change notification settings - Fork 1
/
dummy.js
42 lines (41 loc) · 1.05 KB
/
dummy.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
import React, { Component } from 'react';
import styled from "@emotion/styled";
import axios from "axios";
import Header from "../../components/Header";
const Container = styled.div`
margin-top: 150px;
`;
class SubmitForm extends Component {
state = {
name: '',
};
/* This is where the magic happens
*/
handleSubmit = event => {
event.preventDefault();
const user = {
name: this.state.name
}
axios.post('https://jsonplaceholder.typicode.com/users', { user })
.then(res => {
window.location = "/retrieve" //This line of code will redirect you once the submission is succeed
})
}
handleChange = event => {
this.setState({ name: event.target.value });
}
render() {
return (
<Container>
<Header />
<form onSubmit={this.handleSubmit}>
<label> Person Name:
<input type="text" name="name" onChange={this.handleChange} />
</label>
<button type="submit"> Add </button>
</form>
</Container>
);
}
}
export default SubmitForm;