【问题标题】:React DND, Failed PropType反应DND,失败的PropType
【发布时间】:2016-03-22 20:42:45
【问题描述】:

当我去拖动我的组件时,我的控制台告诉我,当它被声明为 const { connectDragSource, isDraggin } = this.props; 时,我无法清除渲染函数中的 propType。我注意到如果我从 KnightSource 对象中删除 is Dragging 属性,它会修复此错误,但我不知道为什么。

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);

【问题讨论】:

    标签: javascript reactjs react-dnd


    【解决方案1】:

    isDragging(props){return(console.log('dragging'))} 有效的JavaScript?我认为您不能将 console.log 作为返回的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-19
      • 2016-07-27
      • 2015-11-26
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多