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" }; } - inj...

https://www.interviewquestionspdf.com/2017/02/how-could-you-use-state-and-props.html
- 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>
);
}
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>
);
}