Skip to content

Instantly share code, notes, and snippets.

@alesanabriav
Last active February 21, 2017 15:32
Show Gist options
  • Save alesanabriav/f35e10fe99e2d4db8e0e20365068ffac to your computer and use it in GitHub Desktop.
Save alesanabriav/f35e10fe99e2d4db8e0e20365068ffac to your computer and use it in GitHub Desktop.
'use strict';
import multipleRender from './multiple_render';
const contactForm = React.createClass({
getInitialState() {
return {
name: '',
email: ''
}
},
getDefaultProps() {
return {
placeholders: {
name: '',
email: ''
}
}
},
handleChange(field, evt) {
const value = evt.target.value;
this.setState({...this.state, [field]: value});
},
handleSubmit(evt) {
evt.preventDefault();
const data = this.state;
//send data to server via ajax
},
render() {
const { name, email } = this.state;
const { placeholders } = this.props;
return (
<form onSubmit={ this.handleSubmit }>
<input
placeholder={ placeholders.name }
onChange={ this.handleChange.bind(null, 'name') }
value={ name }
/>
<input
placeholder={ placeholders.email }
onChange={ this.handleChange.bind(null, 'email') }
value={ email }
/>
<button>submit</button>
</form>
)
}
});
multipleRender(".contact-form", ContactForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment