Skip to content

Instantly share code, notes, and snippets.

@yashikagarg13
Last active May 6, 2017 06:26
Show Gist options
  • Save yashikagarg13/0dbd4d921f8ffce8aba168cd7402469d to your computer and use it in GitHub Desktop.
Save yashikagarg13/0dbd4d921f8ffce8aba168cd7402469d to your computer and use it in GitHub Desktop.
Jest Blog
class Form extends React.Component {
constructor(props) {
super(props);
this.state = {
input: "",
};
this.onChangeHandler = this.onChangeHandler.bind(this);
this.onSubmitHandler = this.onSubmitHandler.bind(this);
}
onChangeHandler(event) {
this.setState({
input: event.target.value
});
}
onSubmitHandler(event) {
Axios.post("some_url", {data: this.state.input})
.then(response => {
AlertsHelper.show({
type: "success",
message: response.message,
});
})
.catch(error => {
AlertsHelper.show({
type: "error",
message: error.message,
});
});
}
render () {
return (
<form onSubmit={this.onSubmitHandler}>
<input type=“text” onChange={this.onChangeHandler} />
<button type=“submit”>Submit</button>
</form>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment