matthewglassman
5/2/2018 - 3:00 PM

React passing a components State (State vs. Stateless) components pt2

Child is going to receive a prop called name, and display that prop on the screen.

How can you make a component display a prop called name?

To access a prop, use the expression this.props.name-of-prop.

To make a component display something, include that thing in the render function's return statement.

You need to include this.props.name inside of Child's render function's return statement.

is going to pass a prop to a .

That means that a is going to render a . Rendering is the only way for a component to pass props to another component.

Any component rendered by a different component must be included in an export statement.

import React from 'react';

export class Child extends React.Component{
  render(){
    return <h1>Hey, my name is {this.props.name}!</h1>;
  }
}