question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React DOM updating every instant on Drag

See original GitHub issue

I am rendering multiple <Draggable> nodes in my app, using an array stored in the state. With the help of React’s Chrome extension’s “Highlight Updates” I could see that all of the different nodes being rendered using a map function were being re-rendered/updated every instant when I would drag any single node.

This seems like something that shouldn’t be happening, especially considering that I used key prop as suggested by React while rendering a list of objects.

return (
        <React.Fragment>
            {nodes.map(
                node => (
                    <Draggable
                        key={node}        // node is a unique string
                        onStop={this.handleStop}
                        onDrag={this.handleMovement}
                    >
                        <div>
                               // content
                        </div>
                    </Draggable>
               ))}
        </React.Fragment>
    );

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
sreetamdascommented, Nov 18, 2018

Here’s a screencapture to explain the issue; the components get highlighted with the colored boxes whenever they are re-rendered, and red denotes that the component is being rendered very frequently (can be reproduced using the React Devtools).

Screencapture

0reactions
STRMLcommented, Mar 26, 2019

Is your parent re rendering?

On Mon, Mar 25, 2019, 10:32 PM Sreetam Das notifications@github.com wrote:

@STRML https://github.com/STRML of course, the item being dragged is re-rendered, but in this example, every Draggable component (all of the items built using react-draggable, each having a unique key as recommended) gets updated on every instance of Drag of a singular item.

Sorry for pestering you but just wanted to know if this was expected behaviour. And thanks a lot for your time!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mzabriskie/react-draggable/issues/371#issuecomment-476461879, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJFPzjPS13PyJNHso1ZJwOrBqgHO7oQks5vaZTkgaJpZM4YoFZ5 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

React setState not Updating Immediately - Stack Overflow
The reason is that setState is more of a request for the state to change rather than an immediate change. React batches those...
Read more >
You Might Not Need an Effect - React Docs
Then React will “commit” these changes to the DOM, updating the screen. Then React will run your Effects. If your Effect also immediately...
Read more >
How To Handle DOM and Window Events with React
In React apps, you can use event handlers to update state data, trigger prop changes, or prevent default browser actions. To do this,...
Read more >
Fetching Data and Updating State in a React Class | Pluralsight
I want to explain how to go about updating component state within a class component with data fetched from a server and hopefully...
Read more >
react-beautiful-dnd/responders.md at master - GitHub
Beautiful and accessible drag and drop for lists with React ... The <Draggable /> and <Droppable /> snapshot updates and any setState caused...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found