Last active
March 26, 2018 13:10
-
-
Save eioo/ff8d6be394670fa1e7c1c119fab39a3f to your computer and use it in GitHub Desktop.
This file contains 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'; | |
interface FormState { | |
name: string; | |
message: string; | |
} | |
class Form extends React.Component<{}, FormState> { | |
constructor(props: {}) { | |
super(props); | |
this.state = { | |
name: '', | |
message: '' | |
}; | |
} | |
handleInputChange = (event: React.FormEvent<HTMLInputElement>) => { | |
this.setState({ | |
name: event.currentTarget.value, | |
message: this.state.message | |
}); | |
} | |
handleTextAreaChange = (event: React.FormEvent<HTMLTextAreaElement>) => { | |
this.setState({ | |
name: this.state.name, | |
message: event.currentTarget.value | |
}); | |
} | |
handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | |
event.preventDefault(); | |
console.log(this.state); | |
} | |
render() { | |
return ( | |
<form onSubmit={this.handleSubmit}> | |
<p>Nimi: <input type="text" name="name" placeholder="Matti Meikäläinen" onChange={this.handleInputChange} /></p> | |
<p>Viesti: <textarea name="message" placeholder="Kirjoita viesti..." onChange={this.handleTextAreaChange} /></p> | |
<button>Lähetä viesti</button> | |
</form> | |
); | |
} | |
} | |
export default Form; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment