Skip to content

Instantly share code, notes, and snippets.

@rishichawda
Created May 19, 2019 08:05
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 rishichawda/e67e17c52c94505a664a18ccb8005537 to your computer and use it in GitHub Desktop.
Save rishichawda/e67e17c52c94505a664a18ccb8005537 to your computer and use it in GitHub Desktop.
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