gpt4 book ai didi

reactjs - 当尝试调用 Apollo Client Query 时,我总是加载 : true, networkStatus: true

转载 作者:行者123 更新时间:2023-12-03 14:27:03 26 4
gpt4 key购买 nike

查询:

HOUSEDETAIL : gql`
query houseDetail($_id:ID){
houseDetail(_id:$_id) {
address
address1
street
phoneNumber
houseNo
}
}
`,

尝试调用apolloClient时React中的代码:

    const Page2 = compose(graphql(query.HOUSEDETAIL,{name:'houseDetail', options: (props) => ({variables: {_id:props.houseAddress._id,fetchPolicy: 'network-only'}})})) (Dashboard) 

浏览器控制台中的错误如下所示:

        props{"houseAddress":{},"houseDetail":{"variables":{"fetchPolicy":"network-only"},"loading":true,"networkStatus":1}}

最佳答案

这似乎是一个常见问题,通常通过添加 notifyOnNetworkStatusChange: true

来解决

在您的具体场景中:

const Page2 = compose(
graphql(
query.HOUSEDETAIL,
{
name:'houseDetail',
options: (props) => ({
variables: {
_id:props.houseAddress._id
}, // ====> this bracket was also misplaced on your example code
fetchPolicy: 'network-only',
notifyOnNetworkStatusChange: true
})
}
)
)(Dashboard)

有关 notifyOnNetworkStatusChange 的更多信息可以在 ReactApollo docs 中找到。 :

关于reactjs - 当尝试调用 Apollo Client Query 时,我总是加载 : true, networkStatus: true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49443434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com