Timing of react componentDidMount

componentDidMount is triggered after the component is indeed rendered into dom. If I append a colored div, that absolutely locates the top0 at this time, the expected effect should be to display the react component first, and then immediately display the red div, but actually directly display the red div, which does not have a flash effect. Why?

class App extends Component {
  constructor(){
    super();
  }
  componentDidMount() {
    const div=document.createElement("div");
    div.style="position:absolute;height:100px;width:100vw;background:blue;top:0";
    document.body.appendChild(div)
  }
  render(){  
    return (
      <div style={{background:"red"}}>hello world</div>
    )
  }
}
Mar.22,2021

is the same as the first floor, this process is invisible to the naked eye. In the same way, if you call api to get the data in the later stage of this life, it is actually called twice, but in the browser, you can't see it at all.


Why do you think modern computers are so slow?
set the delay with setTimeout if you want to see the effect.


part of render is written incorrectly

render() {
    return (
      <div style={{background:'red'}}>hello world</div>
    )
 }

now you should be able to see red and then blue

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b4018c-2c4ca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b4018c-2c4ca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?