facebook / facebook/relay

`useSubscription`: Subscribe / skip based on condition?

Open
#3,814 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

[`useSubscription`](https://relay.dev/docs/api-reference/use-subscription/) as of relay 13 does not have a way to skip invocation based on props passed.

Here are three options that come to mind:

1. Use [`requestSubscription`](https://relay.dev/docs/api-reference/request-subscription/)
2. Separate component. Keep the `useSubscription` there and conditionally render it
3. [relay-tools/relay-hooks](https://github.com/relay-tools/relay-hooks/)'s [`useSubscription`](https://github.com/relay-tools/relay-hooks/blob/v7.0.0/docs/useSubscription.md) w/ [`{ skip: ... }`](https://github.com/relay-tools/relay-hooks/blob/v7.0.0/__tests__/useSubscription-test.tsx#L80) support

What's the background behind `useSubsription` and having or not having `skip`? Do the best practices of hooks (in general) and relay have anything to say for or against it?

Contributor guide

Open the contributing guide

Research direction

Start with the Relay 13 useSubscription API documentation and compare its behavior with requestSubscription and the separate-component approach described in the issue. Review relay-tools/relay-hooks' useSubscription documentation and __tests__/useSubscription-test.tsx for the skip option. The issue does not define a preferred behavior or acceptance criteria, so a design decision would be needed before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.