Created
July 14, 2017 18:42
-
-
Save barberdt/0f43ad3c7242beeb6ef5d33e42e18017 to your computer and use it in GitHub Desktop.
react-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 PropTypes from 'prop-types'; | |
import { connect } from 'react-redux'; | |
import MyComponent from '../components/MyComponent'; | |
import { pressed } from '../actions/actionCreators'; | |
function mapStateToProps({ mySelector: { foo } }) { | |
return { foo }; | |
} | |
const propTypes = { | |
pressed: PropTypes.func.isRequired, | |
}; | |
function MyComponentContainer({ | |
pressed: pressedActionCreator, | |
...restProps, | |
}) { | |
return ( | |
<MyComponent | |
onPress={pressedActionCreator} | |
{...restProps} | |
/> | |
); | |
} | |
export default connect( | |
mapStateToProps, | |
{ pressed }, | |
)(MyComponentContainer); |
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 { connect } from 'react-redux'; | |
import MyComponent from '../components/MyComponent'; | |
import { pressed } from '../actions/actionCreators'; | |
function mapStateToProps({ mySelector: { foo } }) { | |
return { foo }; | |
} | |
export default connect( | |
mapStateToProps, | |
{ onPress: pressed }, | |
)(MyComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment