Is any call monitor.getItemType() return null at the beginDrag function call
what I'm code:
import ItemTypes from 'macro/ItemTypes' ;
const dragSource = {
beginDrag( props , monitor ){
let itemType = monitor.getItemType() ;
console.log( itemType ) ; // always return null whatever I drag any dragsource
// cell 拖拽
if( itemType == ItemTypes.EXIST_CARD ){
let position = props.position ,
arrayIndex = props.arrayIndex ;
return {
type: 'reRank' ,
position ,
arrayIndex
}
}else if( itemType == ItemTypes.ROWCARD ){
return {} ;
}else{
console.warn( '未定义拖拽源' , itemType ) ;
return {} ;
}
} ,
canDrag( props , monitor ){
let itemType = monitor.getItemType() ;
let item = monitor.getItem() ;
console.log( itemType )
if( props.obj ){ // DragInner已经绑定了一个对象 ( 表单控件 描述对象 )
return true ;
}else{
return false ;
}
}
}
export default dragSource ;
At beginDrag function console.log( itemType ) always return null .what evet I drag EXIST_CARD or ROWCARD dragSource .
DragSource:
@DragSource( ItemTypes.EXIST_CARD , dragSource , ( connect , monitor )=>{
return {
connectDragSource: connect.dragSource()
}
} )
export default class DragInner extends Component {
static propTypes = {
connectDropTarget: PropTypes.func.isRequired
}
constructor(props) {
// ...
}
render() {
// ...
return connectDragSource(
connectDropTarget(
<div className={className} style={{
minHeight: '30px' ,
backgroundColor ,
}} onClick={this.handleClick}>
{ /*hasDropped && <span>dropped {hasDroppedOnChild && ' on child'}</span>*/ }
{ modelToReact( obj ) }
</div>
)
) ;
}
}
@lcoder monitor are being used for internal state management of DND. When beginDrag (which should return information being passed to target, I am quoting documentation here), is called on DragSource we don't have ItemType information available in state. It would better to separate out the concerns. 'beginDrag' in the example is taking decision for different ItemTypes. If we separate them out, we can get rid of the check.
@anilreddykatta I clear.Thanks!😄
@lcoder Welcome.
@lcoder Can you close this issue?