I’m trying to call the graphq-ws createClient exposed “on” Event from react component
Let’s say I have to call some function api call when user gets disconnect or gets connected
<code> const wsLink = new GraphQLWsLink(
createClient({
url: GRAPHQL_WS_ENDPOINT ?? "",
on: {
closed: () => {
// Need to call from React component
},
opened: () => {
// Need to call from React component
},
},
})
);
</code>
<code> const wsLink = new GraphQLWsLink(
createClient({
url: GRAPHQL_WS_ENDPOINT ?? "",
on: {
closed: () => {
// Need to call from React component
},
opened: () => {
// Need to call from React component
},
},
})
);
</code>
const wsLink = new GraphQLWsLink(
createClient({
url: GRAPHQL_WS_ENDPOINT ?? "",
on: {
closed: () => {
// Need to call from React component
},
opened: () => {
// Need to call from React component
},
},
})
);
I tried to expose the event by making it hook
Firstly create a custom Hook to manage the WebSocket client and expose the opened and closed events.
then Pass callback functions to your hook to handle the opened and closed events within your component.