Reputation: 3593
Does there exist some default props object that is always passed from parent component down to a child component?
I know one can pass props to some children components from a parent component, like:
<div>
<ChildComponent color="blue" otherProp=false />
</div>
and access them in child component via props.color
and props.otherProp
...
but what if I don't create props for my child component, does there still exist some default props
object (or maybe some props meta object) with additional information for that child component?
E.g I have seen some match object that gets automatically created by the React-router library and passed down to its components that are rendered when matching some route path, e.g:
<Route path={`${match.path}/:name`}
render= {({match}) =>( <div> <h3> {match.params.name} </h3></div>)}/>
I was just wondering where in this example, the ({match})
object is coming from when its passed as a parameter to the render prop function....
Upvotes: 3
Views: 1619
Reputation: 1852
If you dont pass the props to the child components, they wont be available to the child component period. Have a look at render props.
Incase of Route
in react router, the Route
passes its props to the children props using composition. So the props of Route
will be available to the immediate child component but wont be available to the next child component hierarchy.
Example:
<Route props={props}>
<Child1>
will have props
<Child2>
will not have props if not passed from Child1
</Child2>
</Child1>
</Route>
Upvotes: 2