通过道具反应DND动态DropTarget

时间:2017-04-02 18:39:53

标签: reactjs drag-and-drop react-dnd

我正在尝试将DND用于2个容器。

1)容器具有静态数据形式axios =>任务清单。 2)容器只有设置为用户的任务。

<Container id={1} list={this.props.tasks}/>
<Container id={2} list={this.state.userTasks}/>

当我更改用户时(通过选择)X =&gt;我必须刷新容器(2)的数据。

我的 this.state.userTasks 正在刷新,但子组件容器(2)仍具有相同的元素。

这是因为我使用构造函数来传递数据。构造函数是一次调用。我知道。

constructor(props) {
        super(props);
        this.state = {cards: props.list};
    }

我无法将 componentWillReceiveProps(nextProps) 用于容器(子),因为我只需要更新容器(2),我将元素从容器移动到容器(2)

时调用此方法

更改用户时如何更新Container(2)卡?你有什么想法?

1 个答案:

答案 0 :(得分:0)

我猜你可以在用户信息发生变化时重置父组件的状态信息来渲染Container组件

componentWillReceiveProps(nextProps){ if (nextProps.userId !== this.props.userId){ this.setState({userTasks : []})} }