Notes for Codefellows Code 401 301 201 and 102
Yes, child components have direct access to props/state passed from the parent component, but only when the parent passes them down to the child component
<main>
<content />
</main>
The child component will be rendered where it is being rendered within the parent component.[credit: Ellis Yoo ]
class Parent extends React.Component {
render(){
return (
<div className = "wrapper">
<h1>{this.props.title}</h1>
{this.props.child}
</div>
)
}
}
class Child extends React.Component {
render(){
return (
<p>{this.props.body}</p>
)
}
}
class App extends React.Component {
render(){
return (
<>
<Parent title="this is parent"}>
<Child body="this is child/>
</Parent>
</>
)
}
}
The following code above produces this markup
<div class="wrapper">
<h1>this is parent</h1>
<p>this is child</p>
</div>
Yes, you can have reuse components in other places in your application.
medium You can use …, which is the spread operator to pass all props to the child .
source used to display whatever you include between the opening and closing tags when invoking a component.
source development pattern based on React’s original component model where we build components from other components using explicit defined props or the implicit children prop.
Skim the following materials in preparation for the upcoming lecture. Note the following as you browse the material, and be prepared to participate in discussions during lecture