Wednesday, 1 February 2017

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>
);
}

WHAT OTHERS ARE READING/RELATED TO THIS:

0 comments:

Post a Comment