I think he’s showing that it works with that example. I like the idea of doing everything in render. Using the meteor hook does something similar by default, where it always runs when react renders, and also forces re-render if something changes reactively. With deps it only reruns if the reactive source changes (or if deps change - the React folks use fancy sounding words like “memoize” to describe this).
Pretty neat really. I have similar but more complicated ideas about how to set up use in render methods type stuff, and this has me thinking of ways to do it.
Getting it to work as a hook eluded me. I think you might have to do something like material-ui’s makeStyles method, that creates a hook for you. I haven’t really looked at it though.
A few of us have implemented a hook in this PR (from this fork). You just use it like a normal hook (with an interface that mimics useEffect or useMemo in its use of a deps param) :
This is not as integrated feeling as your solution, which allows you to simply use reactive meteor sources in the entire render function. I like that approach, and I’m now thinking about how to make that work for various sources without requiring the hook at all, or at least without tracker. We could create a distinct hook for each API - for example, a new set of search hooks could be used. Instead of MyCollection.find we could have a MyCollection.useFind which would set up reactivity using the observeChanges API directly, instead of using Tracker (I’m thinking we can gain some render efficiency doing this, but I’m not sure yet). Similarly, a subscription hook could manage the subscription without even needing to use Tracker (or could use a simple tracker implementation based on useEffect which would simplify many of the stickier implementation details in our useTracker hook…).
I made a couple of improvements including stopping the subscription when the component unmounts, and fixed a bug that caused the tracker to duplicate itself every render