3

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);
Justin E. Samuels
  • 867
  • 10
  • 28

1 Answers1

0

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.

Ben Hare
  • 4,365
  • 5
  • 27
  • 44