Add enabled option to useTable hook#4721
Open
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
Open
Add enabled option to useTable hook#4721DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
This adds an
enabledoption to theuseTablehook in the React SDK, allowing devs to conditionally disable a subscription without having to wrap it in a component that is conditionally mounted.With
enabled, you can control subscription lifecycle as such:This is a similar pattern in other data hooks (React Query's
useQuery, SWR, Apollo'suseSubscription, etc).When
enabledisfalse:computeSnapshotreturns[[], true]immediately (no data, ready state)subscribeAppliedWhen
enabledflips back totrue, the subscription is re-established automatically via the dependency arrays.API and ABI breaking changes
None. The
enabledfield is optional and defaults totrue, so existing usage is unaffected.Expected complexity level and risk
1 — Single file change, additive only. The
enabledflag gates existing behavior behind early returns and is wired into the existing dependency arrays. No interaction with other components.Testing I Did
useTable(tables.foo)works as before (noenabledoption passed)useTable(tables.foo, { enabled: false })returns[[], true]and does not subscribeenabledfromfalsetotrueestablishes the subscription and returns rowsenabledfromtruetofalseclears rows and unsubscribes