I have a project using React and want to get width of an HTML element, but when adding document.querySelector(myElelment).clientWidth
in componentDidMount()
It return an uncorrect value. I assume that componentDidMount() is invoked after Virtual DOM is mounted but Real DOM isn't finishing yet. Is that true ?
Asked
Active
Viewed 156 times
1

QUANG Tuấn Vũ
- 111
- 2
- 9
-
Does this answer your question? [When exactly is \`componentDidMount\` fired?](https://stackoverflow.com/questions/36049493/when-exactly-is-componentdidmount-fired) – Ilmari Karonen Jul 13 '20 at 16:30
-
@ Ilmari Karonen : Thanks, but your topic you gave isn't things that I find – QUANG Tuấn Vũ Jul 14 '20 at 03:53
-
@Evert : useRef is only used for stateless component, How could I do that with it ? – QUANG Tuấn Vũ Jul 14 '20 at 03:56