Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

useSubscription triggers unnecessary rerenders #3549

@borremosch

Description

@borremosch

I am using useSubscription in one of my components. I do not use any of the return values, because I am using a complicated protocol in my subscription, and I do not want to act on every message I receive. Instead, I am using the onSubscriptionData callback function. I was surprised to see that even though I only update state on some of the received messages, my component is rerendering continuously. It seems that using useSubscription will trigger a re-render every time subscription data is received, even if it is discarded.

It would be very useful to have a version of useSubscription that does not trigger a re-render whenever data is received, and instead let the user decide when to make state changes in onSubscriptionData. For now, I have had to put my subscription in a sub-component, just to make the superfluous re-rendering computationally cheaper.

I am using @apollo/react-hooks version 3.1.2.

  System:
    OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo)
  Binaries:
    Node: 10.16.0 - /usr/bin/node
    Yarn: 1.19.0 - /usr/bin/yarn
    npm: 6.10.0 - ~/cubonacci/services/ui/node_modules/.bin/npm
  Browsers:
    Chrome: 77.0.3865.90
    Firefox: 69.0.1
  npmPackages:
    @apollo/react-components: ^3.1.2 => 3.1.2 
    @apollo/react-hoc: ^3.1.2 => 3.1.2 
    @apollo/react-hooks: ^3.1.2 => 3.1.2 
    apollo-cache-inmemory: ^1.6.3 => 1.6.3 
    apollo-client: ^2.6.4 => 2.6.4 
    apollo-link-http: ^1.5.16 => 1.5.16 
    apollo-link-ws: ^1.0.19 => 1.0.19 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions