Reactjs Graphql onCreate订阅触发多次
当使用Reactjs Graphql onCreate订阅触发多次,reactjs,graphql,aws-amplify,Reactjs,Graphql,Aws Amplify,当使用组件列出和侦听突变时,我在react中出现了这个开-关-关-再错误。通常,当我执行创建变异时,订阅应返回我刚刚创建的1个结果,但有时当我执行此操作时,订阅会返回相同结果的多个副本,然后我会得到错误 prev.listPatients is undefined 下面您可以看到我的连接组件 <Connect query={graphqlOperation(listPatients)}
组件列出和侦听突变时,我在react中出现了这个开-关-关-再错误。通常,当我执行创建变异时,订阅应返回我刚刚创建的1个结果,但有时当我执行此操作时,订阅会返回相同结果的多个副本,然后我会得到错误
prev.listPatients is undefined
下面您可以看到我的连接组件
<Connect
query={graphqlOperation(listPatients)}
subscription={graphqlOperation(onCreatePatient)}
onSubscriptionMsg={(prev, updatedQuery) => {
//console.log("checkme",updatedQuery)
//return prev;
let updatedQuerys = {...prev};
var PatientList = [
updatedQuery.onCreatePatient,
...prev.listPatients.items
]
updatedQuerys.listPatients.items = PatientList
console.log("checkme",prev)
console.log("checkmes",updatedQuerys)
console.log("checkmus",updatedQuery)
return updatedQuerys
}}
>
{
//log(“checkme”,updatedQuery)
//返回上一个;
让updatedQuerys={…prev};
var PatientList=[
updatedQuery.onCreatePatient,
…prev.listPatients.items
]
updatedQuerys.listPatients.items=PatientList
console.log(“checkme”,prev)
log(“checkmes”,updatedQuerys)
log(“checkmus”,updatedQuery)
返回更新的查询
}}
>
希望有人知道我能做些什么。
谢谢