简体   繁体   中英

React DND, Failed PropType

I'm stuck on how when I go to drag my component, my console is telling me that I've failed to declear the propType inside my render function, when it's declared as const { connectDragSource, isDraggin } = this.props; . I've noticed if I remove the is Dragging property from my KnightSource object, that it fixes this error, but I have no clue as to why.

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

Is isDragging(props){return(console.log('dragging'))} valid javascript? I don't think you can have the console.log as the value that is being returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM