Last active
November 17, 2018 16:34
-
-
Save oreqizer/0bb942a0975359ce7de74f1a1f3142fc to your computer and use it in GitHub Desktop.
Kiki's thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
class RestPost extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { firstName: "", lastName: "", country: "", university: "" }; | |
this.handleChange = this.handleChange.bind(this); | |
this.handleSubmit = this.handleSubmit.bind(this); | |
} | |
handleChange(event) { | |
const target = event.target; | |
const name = target.name; | |
this.setState({ [name]: target.value }); | |
} | |
handleSubmit() { | |
alert(`User created ${this.state.lastName}`); | |
this.createBlogPost(); | |
} | |
createBlogPost() { | |
// const { firstName, lastName } = this.state; | |
const firstName = this.state.firstName; | |
const lastName = this.state.lastName; | |
return fetch("http://localhost:8080/REST/saveStudent", { | |
method: "POST", | |
body: JSON.stringify({ | |
firstName, | |
lastName, | |
}), | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
}) | |
.then(res => res) | |
.catch(err => err); | |
} | |
render() { | |
return ( | |
<form onSubmit={this.handleSubmit}> | |
<label> | |
First name:{" "} | |
<input name="firstName" value={this.state.firstName} onChange={this.handleChange} /> | |
</label> | |
<br /> | |
<label> | |
Last name:{" "} | |
<input name="lastName" value={this.state.lastName} onChange={this.handleChange} /> | |
</label> | |
<br /> | |
<label> | |
Country | |
<select name="country" value={this.state.country} onChange={this.handleChange}> | |
<option hidden="hidden">Choose one</option> | |
<option value="Slovakia">Slovakia</option> | |
<option value="Czech republic">Czech republic</option> | |
<option value="Poland">Poland</option> | |
<option value="Germany">Germany</option> | |
<option value="Hungary">Hungary</option> | |
</select> | |
</label> | |
<br /> | |
<label> | |
University | |
<select name="university" value={this.state.university} onChange={this.handleChange}> | |
<option hidden="hidden">Choose one</option> | |
<option value="1">VŠE</option> | |
<option value="2">UK</option> | |
<option value="3">None</option> | |
</select> | |
</label> | |
<br /> | |
<input type="submit" value="Submit" /> | |
</form> | |
); | |
} | |
} | |
export default RestPost; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment