-
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The query hooks ( Your question does expose a gap in covered functionality -- there is no way to have a component listen to all changes made to all documents that match a query. However, I haven't personally encountered a use case for that. It would be possible to create this behavior yourself if you absolutely need it by manually subscribing to all documents in the query... const lists = hooks.useAllLists();
const [_, setForceUpdateValue] = useState(0);
useEffect(() => {
const forceUpdate = () => setForceUpdateValue(v => v+1);
const unsubscribes = lists.map(list => list.subscribe('changeDeep', forceUpdate));
return () => {
unsubscribes.forEach(unsub => unsub());
};
}, [lists]); It's not elegant, but it's also not recommended that one component respond to every single change in a set of documents. Instead, pass the individual documents to components that monitor for granular changes. |
Beta Was this translation helpful? Give feedback.
The query hooks (
useX
,useOneX
,useAllX
) are only meant to update when documents are added or removed from the query itself. They will not trigger a re-render if the contents of those documents change. To watch for changes to document contents, usehooks.useWatch(doc)
, passing the document you want to monitor. If you want to watch for any deep changes to a single document, you can also pass{ deep: true }
as a second parameter, and it will watch for any changes in nested levels of the document, too.Your question does expose a gap in covered functionality -- there is no way to have a component listen to all changes made to all documents that match a query. However, I haven't personally en…