Last active
February 21, 2017 15:32
-
-
Save alesanabriav/f35e10fe99e2d4db8e0e20365068ffac 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
'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