当我去拖动我的组件时,我的问题仍然存在,我的控制台告诉我,当我的渲染函数声明为const { connectDragSource, isDraggin } = this.props;
时,我无法清除渲染函数中的propType。我注意到我是否从我的KnightSource对象中删除了“拖动”属性,它修复了这个错误,但我不知道为什么。
import React, { Component, PropTypes } from 'react';
import { ItemTypes } from './Constants';
import { DragSource } from 'react-dnd';
const knightSource = {
beginDrag(props) {
return {};
},
isDragging(props){
return(console.log('dragging'))
}
};
function collect(connect, monitor) {
return {
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
}
}
class Knight extends Component {
render() {
const { connectDragSource, isDragging } = this.props;
return connectDragSource(
<div style={{
opacity: isDragging ? 0.5 : 1,
fontSize: 100,
fontWeight: 'bold',
cursor: 'move',
color: isDragging ? 'blue' : 'green'
}}>
♘
</div>
);
}
}
Knight.propTypes = {
connectDragSource: PropTypes.func.isRequired,
isDragging: PropTypes.bool.isRequired
};
export default DragSource(ItemTypes.STUDENT, knightSource, collect)(Knight);
答案 0 :(得分:0)
是isDragging(props){return(console.log('dragging'))}
有效的JavaScript?我不认为你可以将console.log作为返回的值。