因此,我尝试使用CLIENT_UPDATED
订阅,但是当我更新列表中的客户端时,将显示另外两个具有相同id
的对象,并且Encountered two children with the same key
错误会显示在控制台。
这是我用来使用订阅的代码
React.useEffect(() => {
setLoading(true)
subscribeToMore({
document: CLIENT_UPDATED,
updateQuery: (prev, { subscriptionData }) => {
if (!subscriptionData.data) return prev;
const newClientItem = subscriptionData.data.clientUpdated;
return {
getClients: [...prev.getClients, newClientItem]
};
}
})
if (data) {
setAllClients(data.getClients)
setLoading(false)
}
}, [data, subscribeToMore])
有什么主意,怎么避免这种乘法发生?