I just would like to show the word "Jack" first, and then after a few seconds, to show another number: 20. But React.js always show them together at the same time. Btw, I know how to use timeout, I just confused why the following code did not run line by line?!
import React from 'react';
import '../index.scss'
class MyForm extends React.Component {
constructor(props) {
super(props);
this.state = {
username: '',
age: null,
};
}
longTimeFunction(input) {
var i = 0;
while(i < input) {
console.log(i)
i = i + 1
}
};
componentDidMount() {
this.setState({ username: 'JACK' })
this.longTimeFunction(30000);
this.setState({ age: '20' })
}
render() {
return (
<h1>Hello: {this.state.username} {this.state.age}</h1>
);
}
}
export default MyForm;