To realize the effect of componentDidMount(), I wrote the following code segment:
class Blink extends Component {
constructor(props) {
super(props);
this.state = {output: 'c'};
}
componentWillMount() {
this.state.output += 'w';
}
render() {
this.state.output += 'r';
let display = this.state.output;
return (
<Text>{display}</Text>
);
}
componentDidMount() {
this.state.output += 'd';
this.setState();
}
}
export default class BlinkApp extends Component {
render() {
return (
<View>
<Blink text='I love to blink' />
<Blink text='Yes blinking is so great' />
<Blink text='Why did they ever take this out of HTML' />
<Blink text='Look at me look at me look at me' />
</View>
);
}
I expected to see four lines of 'cwrdr' according to two reasons:
The execution order: constructor(props)->componentWillMount()->render()->componentDidMount()
setState() called in componentDidMount() will invoke render() again.
Please kindly share your thoughts on my code and reasoning. Much appreciated.