Skip to content

Instantly share code, notes, and snippets.

@barberdt
Created July 14, 2017 18:42
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 barberdt/0f43ad3c7242beeb6ef5d33e42e18017 to your computer and use it in GitHub Desktop.
Save barberdt/0f43ad3c7242beeb6ef5d33e42e18017 to your computer and use it in GitHub Desktop.
react-redux
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);
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