Inside a react component tree, componentDidMount()
is fired after all children components have also been mounted. This means, that any component's componentDidMount()
is fired before its parent has been mounted.
So if you want to measure DOM position and sizes etc, using componentDidMount()
of a child component is an unsafe place/ time to do this.
In your case: to get accurate reading from 100% width/height components, a safe place to take such measurements would be inside the componentDidMount()
of the top react component.
100% is a width/height relative to the parent/ container. So measurements can only be taken after the parent has been mounted too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…