Normally you can access props sent by parent to child on child component. But when redux is used on child components the props sent by parent is lost with use of 'connect' method which maps redux state with components props.
E.g.:
Declaring a component with properties:
<A_Component prop1='1' prop2='2' />
Accessing without redux on child component, works fine:
this.props.prop1
or this.props.prop2
Same statements will give undefined
error if redux states are used.
Own component props are available as second argument of mapStateToProps
function:
// ParentComponent.js
// ... other component methods ...
render() {
return <TodoContainer id="1" />
}
// TodoContainer.js
// `ownProps` variable contains own component props
function mapStateToProps(state, ownProps) {
return {
todo: state.todos[ownProps.id]
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With