Skip to content

Add enabled option to useTable hook#4721

Open
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson:feature/enabled-option-to-use-table
Open

Add enabled option to useTable hook#4721
DexterKoelson wants to merge 1 commit intoclockworklabs:masterfrom
DexterKoelson:feature/enabled-option-to-use-table

Conversation

@DexterKoelson
Copy link
Copy Markdown

Description of Changes

This adds an enabled option to the useTable hook 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:

const [rows, isReady] = useTable(tables.messages, { enabled: isChatOpen });

This is a similar pattern in other data hooks (React Query's useQuery, SWR, Apollo's useSubscription, etc).

When enabled is false:

  • computeSnapshot returns [[], true] immediately (no data, ready state)
  • The subscription effect skips setup and resets subscribeApplied
  • The event listener callback returns a no-op cleanup

When enabled flips back to true, the subscription is re-established automatically via the dependency arrays.

API and ABI breaking changes

None. The enabled field is optional and defaults to true, so existing usage is unaffected.

Expected complexity level and risk

1 — Single file change, additive only. The enabled flag gates existing behavior behind early returns and is wired into the existing dependency arrays. No interaction with other components.

Testing I Did

  • Verify useTable(tables.foo) works as before (no enabled option passed)
  • Verify useTable(tables.foo, { enabled: false }) returns [[], true] and does not subscribe
  • Verify toggling enabled from false to true establishes the subscription and returns rows
  • Verify toggling enabled from true to false clears rows and unsubscribes

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants