Many of you might have heard of GraphQL. It provides QUERY
and MUTATION
. Also it supports SUBSCRIPTION
as 100% replacement of web socket
. I'm a big fan of GraphQL and hooks. Today I faced an issue with useSubscription
which is a hook version of SUBSCRIPTION
. When this subscription is fired, a React component is re-rendered. I'm not sure why it causes re-rendering.
import React from 'react'
import { useSubscription } from 'react-apollo'
const Dashboard = () => {
...
useSubscription(query, {
onSubscriptionData: data => {
...
}
})
render (
<>
Dashboard
</>
)
}
Actually useSubscription
's API doc doesn't say anything about this re-rendering now. It would be really appreciated if you provide me a good solution to preventing the re-rendering.
Thanks!