Hi,
Is there an easy way to identify the new / changed data from pub/sub on the client?
I am using Grapher withQuery.
My initial plan was to track the previous pub/sub state using a custom usePrevious React hook and check for differences, but I wondered if there was a Meteor/Grapher way to do this already?
Thanks,
Alex
If I understand you correctly, you want to tap into the event when pub/sub data gets changed, and you also want to have the pubsub state before the change. A react class component’s componentDidUpdate(prevProps)
might give you just that.
But that’s conspicuously easy, so you probably have meant something else
Hi @peterfkruger,
Yes, pretty much. I need to do something different depending on what is different with the newly published data.
For example, if a new document has been added, I want to do X. If the change was caused by an existing document changing, then I don’t want to do anything.
I was just wondering if Meteor or Grapher had some built-in functionality to check this.
I guess not - I’ll go with the prevProps method instead.
You should check out Cursor.observe (and observeChanges).
You’d probably want to set that up in useEffect
instead of using useTracker
if you use those.
1 Like