简体   繁体   中英

In react Resizing an element with mouse, what is the best way to implement with render function or directly change div width and height?

When we resize a div element using mouse move event should we re-render the element using render function or directly modify div's height and width.

The proper way to modify an element is go through render function but for each mouse move pixel the render function is called which might cause some load on browser.

While directly modifying the width and height will have no load is what i feel.

Which is a better way?

If you use React then it's better to do it React way. Changing components state on all kinds of events ( mousemove , resize , etc) is a common practice. I don't think you'll notice any lags in a browser (I believe it may get laggy if you have 1000+ such components which change their state at the same time).

So you better set event listener on your component and change its state when event triggers. Then in your render function use updated state.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM