2017-04-02 83 views
0

我想为2个容器使用DND。React DND动态DropTarget由道具

1)容器有静态数据表单axios =>任务列表。 2)容器只有设置给用户的任务。

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

当我改变用户(通过选择)X =>ÿ我必须刷新数据为容器(2)

this.state.userTasks是令人耳目一新,但子组件容器(2)仍然有相同的元素。

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

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

我不能使用componentWillReceiveProps(nextProps)集装箱(孩子),因为我只更新容器(2),当我从集装箱移动元素集装箱此方法调用(2)

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

+0

? –

回答

0

我想你可以重置父组件的状态信息,其中要渲染Container组件时用户信息您使用的任何存储/状态管理框架如助焊剂或Redux的改变

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