Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Is there any way to return the classname of the drop target using react-dnd?

Let's say I have this component, which represents a drop target.

import { useDrop } from 'react-dnd';
import './css/DraggableGameSlot.css';

type DraggableGameSlotProps = {
    className: string,
    text: string
}

function DraggableGameSlot(props: DraggableGameSlotProps) {        
    const [{isOver}, drop] = useDrop(() => ({
        accept: "image",
        collect: (monitor) => ({
            isOver: !!monitor.isOver(),
        })
    }))
      
    return (
        <div className={`draggable-game-slot ${props.className}`} ref={drop}>
            <span>Drop here</span>
        </div>
    )
}

export default DraggableGameSlot;

When there is an item dropped on the div, I want to get the className of the div (console.log would be fine, I will implement the logic I want myself)

How should I modify the code to get this functionality?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to the react-dnd useDrop documentation the useDrop hook returns

Return Value Array

  • [0] - Collected Props: An object containing collected properties from the collect function. If no collectfunction is defined, an empty object is returned.
  • [1] - DropTarget Ref: A connector function for the drop target. This must be attached to the drop-target portion of the DOM.

So, having the DropTarget Ref you should be able to do something like drop.current.classList to get the classes of the drop target html element.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!