react-rnd icon indicating copy to clipboard operation
react-rnd copied to clipboard

Unnecessary re-render of other elements when using controlled RND

Open TheGameNewWorldOrder opened this issue 4 years ago • 2 comments

Is it a bug/feature/question or do you need help? question, improvement

Overview of the problem

I'm using react-rnd version [10.3.1]

My browser is: Chrome

I am sure this issue is not a duplicate? Not sure

Reproduced project

https://codesandbox.io/s/react-end-controlled-re-render-in2f7

Description

Steps to Reproduce

  1. Create controlled Rnd with position and size
  2. Create a sibling normal div without any specified props
  3. Add console log in normal div

Expected behavior

there is only one console log output as the div is initially mounted

Actual behavior

There is a console log output every time when you click/drag/resize the Rnd element.

With uncontrolled Rnd(default prop only), there is no extra re-rendering of the other element regardless your actions on the Rnd.

Why would controlled Rnd trigger the re-rendering but the uncontrolled won't?

TheGameNewWorldOrder avatar Jun 22 '21 05:06 TheGameNewWorldOrder

Is it really a problem with Rnd ? As I see it, it renders eveytime the App state changes, nothing unusual.

challet avatar Sep 01 '21 08:09 challet

The parent component's re-rendering causes the child component's re-rendering.

You can just wrap Rnd with a new wrapper component. That way, the parent component will no longer be re-rendered after you dragging or resizing it.

Check this out https://codesandbox.io/s/react-end-controlled-re-render-forked-zgumn?file=/src/index.js

fridaythx avatar Sep 24 '21 16:09 fridaythx