Hi, I just published a small package because I thought more people could be interested. I put it on NPM because with Atmosphere I got a duplicate React versions error, and the typings didn’t work. If someone can help me with that, I would appreciate it
Package: meteor-subscribe-suspense
Github repo: https://github.com/rijk/meteor-subscribe-suspense
What it basically allows you to do is the following:
function Board({ id }) {
useSubscription( 'board', id )
// No need for ready checks; when you get here the subscription is ready
return <div>Board {id}</div>
}
And then ‘catch’ the loading state in a parent component (similar to how Error Boundaries work):
function App() {
return (
<Suspense fallback={<b>Loading…</b>}>
<Board id={123} />
</Suspense>
)
}
In addition, because we have to keep a cache for Suspense anyway, we can add cool things like preloading:
<NavLink
to={`/board/${board.id}`}
onMouseEnter={() => {
subscriptions.preload( 'board', board.id )
}}
>
{board.name}
</NavLink>
Checkout the readme for more details and examples, and feel free to check out the code. It’s relatively small as most of the Suspense related work is done by use-asset
.
Let me know what you think!