2016-03-22 11 views
3

Bileşenimi ne zaman sürüklemeye gittiğimde takılıyorum, konsolum, const { connectDragSource, isDraggin } = this.props; olarak bildirildiğinde, benim render işlevimin içindeki propType öğesinin ne olduğunu açıklamam gerektiğini söyledi. KnightSource nesnesinden Dragging özelliğini kaldırırsam, bu hatayı düzelttiğimi farkettim, ancak neden diye bir fikrim yok.React DND, Başarısız PropType

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

cevap

0

isDragging(props){return(console.log('dragging'))} geçerli javascript var mı? Console.log'un döndürülen değer olarak sahip olabileceğini düşünmüyorum.