meteor / react-packages

Meteor packages for a great React developer experience
http://guide.meteor.com/react.html
Other
571 stars 157 forks source link

useTracker and concurrent mode/suspense #336

Open OliverColeman opened 3 years ago

OliverColeman commented 3 years ago

Just wondering how or if it's possible to integrate React Suspense with useTracker. The documentation about useTracker mentions Suspense integration, but I can find no examples of this. I think the Suspense API requires data loaders to throw a promise when data is loading (?), and after a quick scan of the useTracker code it looks like useTracker itself doesn't do this, so perhaps it's not possible out of the box?

CaptainN commented 3 years ago

useTracker supports suspense in that it will work, and properly clean up in suspended scenarios. The same goes for error boundaries and concurrent mode. It doesn't support throwing promises though, for a bunch of complexity reasons. Basically, computations are very flexible, and there are a lot of edge cases to consider.

It should be fairly straight forward to use a separate hook though. Meteor.subscribe supports a callback in it's use. You could tie that to a Promise and throw it, and use it that way to get suspense. Then use useTracker only for your queries.

CaptainN commented 3 years ago

BTW, useTracker without deps array might "just work" with suspense.