我如何收听订阅并在收到内容时使用缓存来保存它?
How can I listen to a Subscription and when recieving something, use the cache to save it?
当你执行 Query
时,你可以只传递一个 update
函数:
<Query
{...}
update={(cache) => {
// do your cache logic
}}
>
但是 Subscription
上没有 update
参数。做什么?
当您使用 <Subscription>
组件时,每次出现 event/update.
时都会调用 renderProps 函数
<Subscription {...} >
{({data, loading}) => {
// Do something here
}}
</Subscription>
您甚至可以在没有 HoC 的情况下使用该功能,但似乎需要一些工作:https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClient.subscribe
当你执行 Query
时,你可以只传递一个 update
函数:
<Query
{...}
update={(cache) => {
// do your cache logic
}}
>
但是 Subscription
上没有 update
参数。做什么?
当您使用 <Subscription>
组件时,每次出现 event/update.
<Subscription {...} >
{({data, loading}) => {
// Do something here
}}
</Subscription>
您甚至可以在没有 HoC 的情况下使用该功能,但似乎需要一些工作:https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClient.subscribe