One can pass props to a component of a child route (while using React Router) by passing the props to the Route
component for the child component and accessing it in the child component of this route by this.props.route.propName
.
What about the props needed in a child component is a portion of the state of its parent component and not just some unrelated data to the components?
Since
in
<Router />
the state of a parentApp
is not in scope, one cannot pass it to component in a sub<Route />
, orall reference to a child component in the parent component is
{this.props.children}
and not<aComponent data={this.state.somePortion} />
, one, again, cannot pass it through the syntax of expression{this.props.children}
.
What is the catch?
redux store
in upper in the main component and provided by a<Provider/>
component in binding libraryreact-redux
all the components in the Router hierarchy can be fed by state by passing as props and accessing in component withthis.props.route.propName
. Thanks. But applying redux to my set up seems a bit difficult to me. Any solution without it. There MUST be some way, and not cumbersome too much. – sçuçu