GraphQL订阅未更新客户端对象

时间:2020-07-15 14:17:41

标签: javascript graphql

因此,我尝试使用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])

有什么主意,怎么避免这种乘法发生?

0 个答案:

没有答案