useDndMonitor() hook always re-renders the component instead of firing callbacks
See original GitHub issueDoc says
The `useDndMonitor` hook can be used within components wrapped in a DndContext provider to monitor the different drag and drop events that happen for that DndContext
Example:
useDndMonitor({
onDrop: () => {
// this callback will get call when the drop occurs
}
});
From the above signature, My understanding was that, onDrop will be called when user drop item on the droppable.
But it re-renders the component on each mouse move. It should not re-renders the component. It should only call the callback.
Here is demo Link https://codesandbox.io/s/dndkit-issue-demo-m5xc7j?file=/src/App.js
This makes this hook un-usable since it re-renders always regardless of an event i wish to get notify.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
React Hooks - Understanding Component Re-renders - Medium
This post is a result of my explorations to understand how each built-in hook influences the component re-renders/lifecycle.
Read more >React Hooks useCallback causes child to re-render
So how would I go about making this onClick function within a functional component without having the children re-render? Is it at all...
Read more >Hooks API Reference - React
It accepts a new state value and enqueues a re-render of the component. ... re-renders, the first value returned by useState will always...
Read more >5 Ways to Avoid React Component Re-Renderings
1. Memoization using useMemo() and UseCallback() Hooks. Memoization enables your code to re-render components only if there's a change in the props. With...
Read more >Understanding common frustrations with React Hooks
“React Hook cannot be called inside a callback”; “React Hooks must be called in a React function component or a custom React Hook...
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 FreeTop 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
Top GitHub Comments
@clauderic i have solved the issue outside of this package using the principle of
use-context-selector
package. Here is the code:https://codesandbox.io/s/dndkit-issue-demo-m5xc7j?file=/src/dndmonitor.js
if this is fine, we can change the MonitorContext inside the src code as subscribe/notify.
This would be ideal yes, as it would also be synchronous rather than the current asynchronous approach. Unfortunately this isn’t something I have time to into at the moment as there are higher priority issues for me to focus on. If this is something you need, I would gladly accept a PR where we can discuss this further.