Languages
[Edit]
EN

React - get react component size before render operation

6 points
Created by:
Kevin
797

In this article, we're going to have a look at how to get component size before rendering in React.

Notes:

  • read this article to see simple custom AutoSizer implementation,
  • read this article to see external library that providesAutoSizer component.

1. Getting element size with functional component

Edit

In this axample useRef function with ref attribute are used to get current size of element. Container component is created with function based approach.

2. Getting element size with class component

Edit

In this axample ref attribute is used to get element reference. Container componen is created with class based approach.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS

React - get react component size
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join