Skip to content

Instantly share code, notes, and snippets.

@aakashns
Created December 5, 2017 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakashns/d3ee3e12ef5e35c811e3490c03d3a0f7 to your computer and use it in GitHub Desktop.
Save aakashns/d3ee3e12ef5e35c811e3490c03d3a0f7 to your computer and use it in GitHub Desktop.
Connecting the contactForm reducer with a React component.
const ContactForm = ({ data, editData }) => (
<div>
<h4>Contact Form</h4>
<input
type="text"
value={data.name}
onChange={e => editData({ name: e.target.value })}
/>
<input
type="text"
value={data.email}
onChange={e => editData({ email: e.target.value })}
/>
<input
type="checkbox"
checked={data.subscribeToNewsletter}
onChange={e => editData({ subscribeToNewsletter: e.target.checked })}
/>
</div>
);
const mapStateToProps = state => ({
data: state.contactForm
});
const mapDispatchToProps = {
editData: editContactForm
};
export default connect(mapStateToProps, mapDispatchToProps)(ContactForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment