Skip to content

Instantly share code, notes, and snippets.

@eioo
Last active March 26, 2018 13:10
Show Gist options
  • Save eioo/ff8d6be394670fa1e7c1c119fab39a3f to your computer and use it in GitHub Desktop.
Save eioo/ff8d6be394670fa1e7c1c119fab39a3f to your computer and use it in GitHub Desktop.
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