Javascript React DnD-嵌套组件可以在放置事件时设置道具,但不能设置父级

Javascript React DnD-嵌套组件可以在放置事件时设置道具,但不能设置父级,javascript,reactjs,Javascript,Reactjs,我有两个DropTargets,ComponentA和ComponentB安排在此结构中: <ComponentA dropEvent={this.handleRootDropEvent} > <p>Displayed Categories </p> { this.state.categories.map((c, idx) => <ComponentB

我有两个DropTargets,ComponentA和ComponentB安排在此结构中:

<ComponentA
    dropEvent={this.handleRootDropEvent}
>
    <p>Displayed Categories </p>
    {   
        this.state.categories.map((c, idx) =>  
            <ComponentB 
                key={idx}
                parentCat={null}
                thisCat={c}
                level={c.level}
                dropEvent={this.handleDropEvent}
            />
        )   
    }   
</ComponentA>
(我可以确认在drop事件中两者都被调用,并且在ComponentA的drop函数中该项不为null)

似乎
component.setState({})
实际上改变了它所调用的组件的道具,或者至少在组件B的情况下我可以这样使用它:

componentWillReceiveProps = () => {
    if (this.props.droppedItem) {
        this.props.dropEvent(this.props.droppedItem, this.props.thisCat)
    }
}
这段代码是有效的,我可以通过检查drop函数中设置的那些道具的存在来触发ComponentB的父组件(或者本例中的祖父母)中的函数

但是,在ComponentA中相同的
组件将接收props
函数定义中,this.props.droppedItem始终未定义


你知道我怎样才能让道具顺利通过吗?我是不是误解了DnD的
组件.setState({}
API?

很抱歉写在这里,但是最后一个问题是这个和
forEach
,你可以使用
forEach
的第二个参数
thisArg
来切换
this
并将
this
放在回调内部,不需要绑定到外部,这可能行不通。@NinaScholz谢谢你,你太好了!这确实解决了我在那里遇到的问题。
componentWillReceiveProps = () => {
    if (this.props.droppedItem) {
        this.props.dropEvent(this.props.droppedItem, this.props.thisCat)
    }
}