Updating state in hover of dragged component and hover component
See original GitHub issueI have a DropTarget and DragSource for the same component and I need to adjust the state on hover of the component being hovered on and the component being dragged. Within hover()
I need to update the state of the component being hovered on and the component being dragged.
I haven’t quite figured out a good way to do this. I can wrap this in another container component and pass props and update the state of the container being hovered on, but how do I update the state of the item being dragged at the same time?
Thank you
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
During drag and drop if any component hover over the current ...
Just changing the value of a variable used in React won't force a rerender - just changing the value of newStyle won't do...
Read more >Add multiple states to components - Adobe Support
In Design mode, click the + button next to the Main component's Default State in the Property Inspector, and select Hover State.
Read more >Dragging Over An Element Without Triggering Hover State
This is an answer to a react-dnd v17 bug. It's still a bug even though it's marked as closed in Github.
Read more >How to implement drag and drop in React with React DnD
At this point, you might be wondering why we need to update the state while hovering? Why not update it while dropping? It's...
Read more >Next steps with React Drag and Drop -- Adding a Drop Target
const workDropTarget = { hover: function(props, monitor, component) { const item = monitor.getItem(); const draggedPosition = item.position; ...
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
I’m needing to do essentially the same thing here: I want to highlight the top or bottom border of the item in a vertical list as the user drags above and below its vertical midpoint, to indicate whether the dropped item would be placed before or after that item.
The Drop Target spec’s
hover
method is called repeatedly - which is fine - as I’ve added some logic to short-circuit execution unless myposition
value actually changes from “above” or “below” (and vice versa). Unfortunately I don’t have a clean mechanism to update the props for thecomponent
instance passed tohover
. I can’t modify theprops
argument nor can I setcomponent.props
- and I think that either would be a bit of a kludge even if possible.The only way I’ve been able to make this work is
props
inside thehover
function on the target specabove
orbelow
is active.This isn’t really ideal since it pollutes my data model with display-only concerns I’d prefer not to mix in there.
Is there some way that
hover
could support a return value which are one or more props to be merged into the props for the specified component? Then I could more easily apply the styling with a component composed around my actual item component.@cliffmeyers If you check out #1096 I found a somewhat more elegant (but still hack-ish) way to do it.