2017-04-02 84 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 : []})} }