我正在尝试将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)卡?你有什么想法?
答案 0 :(得分:0)
我猜你可以在用户信息发生变化时重置父组件的状态信息来渲染Container
组件
componentWillReceiveProps(nextProps){
if (nextProps.userId !== this.props.userId){
this.setState({userTasks : []})}
}