0

I'm using React and ApolloGraphQL in my app.

The component structure is like this (indentation level indicating parent/child component):

App
  Menu
    Description
    ListFoodsContainer
    NewFood

When NewFood is adding a food to the server (which it does succesfully) the subscription is working properly in the GraphQL Playground.

But when I try to use the useSubscription hook in ListFoodsContainer component, the hook's code doesn't trigger

useSubscription(FOOD_ADDED, {
  onSubscriptionData: ({ subscriptionData }) => {
    console.log('Hello from ListFoodsContainer')
  }
})

365体育足球滚球比分(Please note that the problem is not to do with imports: the same imports and hook code work in other components as we'll find out)

Then I try the same hook with the exact same code (excluding the logged message) in the following components:

-App
-Menu
-Description
-NewFood

and the console says

Hello from App
Hello from Menu
Hello from NewFood

So from this I draw the conclusion that the useSubscription hook ONLY WORKS365体育足球滚球比分 in the component that triggers the subscription in the first place, and it's parent components. This is super confusing because that is not what the docs are suggesting

Can somebody either verify my conclusion or nullify it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy365体育足球滚球比分

Browse other questions tagged or ask your own question.