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.
signal
: A signal representing the collection or document to subscribe to.queryParams
(optional): An object containing query parameters when subscribing to multiple documents.Returns a signal representing the subscribed data.
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.
useSub()
should be used within components wrapped with observer()
to ensure proper reactivity.