在我的项目中,我调用了一个操作,该操作进行 Web 服务调用,然后将操作分派(dispatch)到 ws 的结果,这些操作编辑商店。 我的问题在于:
ComponentDidUpdate () {
If (this.props.messages.length) {
Const items = this.props.messages.filter (this.isDisplayable);
This.timer = setInterval (() => {
If (items.length> 0) {
This.props.popItem (items);
} Else {
ClearInterval (this.timer);
}
}, This.props.interval);
}
}
事实上,它已经启动了好几次,并且我收到了警告
Warning: flattenChildren (...): Encountered two children with the same key,
1
. Child keys must be unique; When two children share a key, only the first child will be used.
我使用了componentDidMount,但它在 API 响应之前启动它。
我的问题是: 有没有办法仅在响应我的操作时更新组件,或者传递警告?
最佳答案
试试这个:
componentWillReceiveProps(nextProps) {
if (this.props.messages === nextProps.messages) return;
关于javascript - 当 API 响应时调用 componentDidMount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41981077/