problem description
the props.index of dragging the spec in the target component in the
react dnd plug-in has always been undefined,. How can I get this value?
the environmental background of the problems and what methods you have tried
use React dnd to implement the drag-and-drop function of the React project. In the drag-and-drop target component (Target), the props.index in the method of getting the specObj object in the hover (props, monitor, component) component is always undefined.
Baidu document describes the current props of props: components
individuals also use to pass index to subcomponents in the drag and drop target component (Target.js) template
related codes
...
const cardTarget = {
hover(props, monitor) {
console.log("props-->",props.index); //undefined
//:
}
};
class Target extends Component {
render() {
....
let items = list.map((item, index) => {
return <Source index={index} id={item.id} />
})
return connectDropTarget(<div>{items}</div>)
}
}
...
what result do you expect? What is the error message actually seen?
how can I get the value of props.index in the specObj object method in the hover component?
console print message:
props index--> undefined