Answer the question
In order to leave comments, you need to log in
How to get an element via ref in React-dnd?
Let's say we have a component:
import React, {useRef, useEffect} from 'react'
import {useDrop} from "react-dnd";
const CreateCeil = (props) => {
let [extra, dropShip] = useDrop({
accept:'ship',
drop: (item, monitor) => console.log(item),
collect: monitor => {
if(monitor.isOver() === true) {
props.insertShip(props.props.id, monitor.getItem())
}
}
})
const ref = useRef();
useEffect(() => {
const rect = ref.current.getBoundingClientRect()
console.log(rect)
})
return (
<div ref={[dropShip, ref]} />
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question