-
-
Save rishichawda/e67e17c52c94505a664a18ccb8005537 to your computer and use it in GitHub Desktop.
ChildComponent.js with connect - Managing Application state without Redux
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
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