Skip to content

Instantly share code, notes, and snippets.

@rishichawda rishichawda/ChildComponent.js Secret
Created May 19, 2019

Embed
What would you like to do?
ChildComponent.js with connect - Managing Application state without Redux
import React from 'react';
import { connect } from './redux';
const ChildComponent = ({ count, updateCounter }) => {
return (
<div>
<p>This is the child component</p>
<p>{count}</p>
<button type='button' onClick={updateCounter}>Click me, I can plus one too!</button>
</div>
);
}
const mapState = ({ count }) => ({
count
});
const mapDispatch = (dispatch) => ({
updateCounter: () => dispatch({ type: 'increment' })
});
export default connect(mapState, mapDispatch)(ChildComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.