I don't know if this question has been asked before, but I want to do the following: I am dragging an image and dropping it in a container, but instead of the image being dropped, I want (let's say) an h1 element to be dropped in the container.
Edit: Here's the code for the drag object (the one I'm dragging):
const [{ isDragging }, drag] = useDrag({
type: ItemTypes.SECTION,
collect: monitor => ({
isDragging: !!monitor.isDragging()
})
})
<img src={accreAss1} alt="Accre Asset 1" ref={drag} style={isDragging ? { "cursor": "copy" } : { "cursor": "pointer" }}/>
And here's the code where I want to drop the dragged object:
let children = [];
const [{ canDrop }, drop] = useDrop({
accept: ItemTypes.SECTION,
drop: () => {
children.push(<h1>Heading to be added</h1>/>)
console.log(children)
},
collect: monitor => ({
canDrop: !!monitor.canDrop()
})
})
/* ---- some code ----*/
return (
<section className="container">
{children}
</section>
)
I am seeing the heading in the console but it does not show on the className="container"