Last active
March 5, 2019 19:53
-
-
Save 3nvi/a4e42aee50f9ab93cc8b8bc851bf3ea4 to your computer and use it in GitHub Desktop.
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
// actions.js | |
export const fireAction = item => ({ type: 'ACTION', payload: { item } }); | |
// ExpensiveComponent.jsx | |
import React, { memo } from 'react'; | |
function ExpensiveComponent({ onClick }) { | |
return ( | |
<button onClick={onClick}>click me</button> | |
) | |
} | |
export default memo(ExpensiveComponent); | |
// MyComponent.jsx | |
import React from 'react'; | |
import { connect } from 'react-redux'; | |
import { getItems } from './selectors'; | |
function MyComponent({ item, fireActionWithItem, randomProp }) { | |
return ( | |
<React.Fragment> | |
<button onClick={fireActionWithItem}>{item}</button> | |
<ExpensiveComponent onClick={fireActionWithItem} /> | |
</React.Fragment> | |
) | |
} | |
const mapDispatchToProps = (dispatch, ownProps) => ({ | |
fireActionWithItem: () => dispatch(fireAction(ownProps.item)) | |
}); | |
export default connect(null, mapDispatchToProps)(MyComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment