-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
discussionenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
Problem
Currently, the useSubscription hook requires explicitly passing the component name as a second argument:
const visibleTodos = useSubscription<Todo[]>([SUB_IDS.VISIBLE_TODOS], 'VisibleTodos');This approach is redundant and error-prone, especially when renaming components or copy-pasting code. We'd like to eliminate the need to pass this name manually.
Goals
- Automatically infer the component name inside
useSubscription - Reduce boilerplate and chance of human error
- Keep the manual name as an optional override (fallback)
Proposed Solutions
-
Stack Trace Inspection
- Use
new Error().stackto infer the calling function/component name. - Pros: No changes needed to API.
- Cons: Fragile across environments and minified builds.
- Use
-
React DevTools Integration
- Use
useDebugValueto help with development/debugging without requiring a manual name. - Note: Only improves developer tooling; doesn’t help internally.
- Use
-
Higher-Order Hook or Wrapper
- Wrap
useSubscriptionin a factory that injects the name (e.g. via function naming). - May require project-wide convention or transformation.
- Wrap
-
Build-Time Injection (Babel Macro or Vite Plugin)
- Automatically insert component name at compile time using tooling.
- Pros: Cleanest runtime.
- Cons: Adds build tooling complexity.
Example (ideal usage)
const visibleTodos = useSubscription<Todo[]>([SUB_IDS.VISIBLE_TODOS]);
// No need to pass 'VisibleTodos' manuallyNotes
We should carefully evaluate runtime performance and browser compatibility if using stack traces, or consider a tooling-based solution for production stability.
Metadata
Metadata
Assignees
Labels
discussionenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed