Skip to content
Advertisement

Get viewport/window height in ReactJS

How do I get the viewport height in ReactJS? In normal JavaScript I use

JavaScript

but using ReactJS, I’m not sure how to get this information. My understanding is that

JavaScript

only works for components created. However this is not the case for the document or body element, which could give me height of the window.

Advertisement

Answer

JavaScript

Set the props

JavaScript

viewport height is now available as {this.state.height} in rendering template

Advertisement