Last active
March 29, 2017 13:20
-
-
Save madetech-com/ac558f4045444df1367588ff552a8b22 to your computer and use it in GitHub Desktop.
"Things We Learned Building A Complex React App" post
This file contains hidden or 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
@connect(...) | |
class HomePage extends React.Component { | |
handleContactFormSubmission (e) { | |
e.preventDefault() | |
const formData = { ... } | |
this.props.dispatch(submitContactForm(formData)) | |
} | |
render () { | |
return ( | |
<main><h1>Welcome!</h1></main> | |
<Sidebar onContactFormSubmission={::this.handleContactFormSubmission} /> | |
) | |
} | |
} | |
class Sidebar extends React.Component { | |
render () { | |
return ( | |
<div styleName="sidebar"> | |
<ContactForm onSubmit={::this.props.onContactFormSubmission} /> | |
</div> | |
) | |
} | |
} | |
class ContactForm extends React.Component { | |
render () { | |
return ( | |
<form onSubmit={::this.props.onSubmit}> | |
<input type="text" name="name"> | |
<textarea name="message" /> | |
<button type="submit">Submit</button> | |
</form> | |
) | |
} | |
} |
This file contains hidden or 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
class HomePage extends React.Component { | |
render () { | |
return ( | |
<main><h1>Welcome!</h1></main> | |
<Sidebar /> | |
) | |
} | |
} | |
class Sidebar extends React.Component { | |
render () { | |
return ( | |
<div styleName="sidebar"> | |
<ContactFormWidget /> | |
</div> | |
) | |
} | |
} | |
@connect(...) | |
class ContactFormWidget extends React.Component { | |
handleSubmission (e) { | |
e.preventDefault() | |
const formData = { ... } | |
this.props.dispatch(submitContactForm(formData)) | |
} | |
render () { | |
return ( | |
<form onSubmit={::this.handleSubmission}> | |
<input type="text" name="name"> | |
<textarea name="message" /> | |
<button type="submit">Submit</button> | |
</form> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment