useSub() Hook
The useSub() hook is a React hook that combines the functionality of the sub() function with React's component lifecycle. It's used to subscribe to TeamPlay data within React components.
Syntax
Parameters
signal: A signal representing the collection or document to subscribe to.queryParams(optional): An object containing query parameters when subscribing to multiple documents.
Return Value
Returns a signal representing the subscribed data.
Example
Features
-
Automatic Subscription Management:
useSub()handles subscribing when the component mounts and unsubscribing when it unmounts. -
Suspense Integration: It works seamlessly with React Suspense, automatically handling loading states.
-
Reactivity: Changes to the subscribed data will cause the component to re-render.
Notes
useSub()should be used within components wrapped withobserver()to ensure proper reactivity.- It's designed to work with React's rules of hooks, so it should not be used in conditional statements.