How could you use state and props together when passing data between components?

- set a default value with state (in the constructor)
constructor() {
super();
this.state = {
title: "Welcome"
};
}

- inject that into a child with this.state
render() {
return (
<div>
<Header title={this.state.title} />
</div>
);
}

- access it in any child component with this.props
In Header.js...
render() {
return (
<div>
<Title title={this.props.title} />
</div>
);
}

Comments

Contact Form

Send