First of all, you don't necessarily need the connect
function if you already provide the data by passing it as a prop to the enhancer. In this case you could also use the recompose
library to apply logic to the data. However, in most cases you still need to dispatch actions, so the connect
function from react-redux
would still be required.
When props are passed to a component that is wrapped by a connect
function, they will not be automatically passed down. In order to make these props accessible to the wrapped component, you need to map them from the second argument in the mapStateToProps
function.
Review.enhancer.js
const mapStateToProps = (state, ownProps) => {
return {
review: ownProps.review,
};
};
export default connect(mapStateToProps, null)(Review);
Now only the review prop is being passed down to the wrapped component. However, you should try to avoid doing this, because it couples the enhancer to the container component.
Note that if you want to pass all the props to the wrapped
component, you can omit the parentheses from the arrow
function and use an implicit return.