Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda