I need to know component's width in render method, but getting DOM elements in render method is not possible. Solving problem I found this article . The problem in article is the same as mine.
Solution:
So I can get component width from component's state.
Anybody knows another approach to solve this problem? Thanks.
Well, you don't have to save the width in state, you could grab it each time with ReactDOM.findDOMNode()
, but this is about the best you're going to get. You can't update in render for two reasons:
Tldr: Just go with the method you have, that works just fine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.