React DOM updating every instant on Drag
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:1
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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).Is your parent re rendering?
On Mon, Mar 25, 2019, 10:32 PM Sreetam Das notifications@github.com wrote: