【发布时间】:2020-06-19 21:17:32
【问题描述】:
我目前正在尝试在 useEffect 挂钩中使用来自 apollo v3 的 useSubscription 挂钩更新 GraphQL 订阅:
let containerSubscription = useSubscription<CreatedDateSubscription, CreatedDateSubscriptionVariables>(
gql(containerUpdatedOnCreatedDate),
{
variables: { createdDate: selectedDate },
shouldResubscribe: true, // is this needed?
},
);
// update subscription on date change
React.useEffect(() => {
// how do I update the subscription here?
// setting containerSubscription.variables = ... does not change the subscription
}, [selectedDate]);
我在 apollo 文档中找不到有关如何解决此问题的任何解决方案。
任何帮助将不胜感激!
【问题讨论】:
-
也许你不应该这样做,我也没有找到任何文档,也许是因为你需要取消订阅并重新订阅新变量
-
@Arman 谢谢你,我想到了。但是,我可以在文档中找到有关如何取消订阅和重新订阅的任何文档
标签: reactjs graphql react-hooks apollo