You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-meteor-data/README.md
+73Lines changed: 73 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -231,6 +231,79 @@ export default withTracker({
231
231
})(Foo);
232
232
```
233
233
234
+
#### `useSubscribe(subName, ...args)` A convenient wrapper for subscriptions
235
+
236
+
`useSubscribe` is a convenient short hand for setting up a subscription. It is particularly useful when working with `useFind`, which should NOT be used for setting up subscriptions. At its core, it is a very simple wrapper around `useTracker` (with no deps) to create the subscription in a safe way, and allows you to avoid some of the cerimony around defining a factory and defining deps. Just pass the name of your subscription, and your arguments.
237
+
238
+
`useSubscribe` returns an `isLoading` function. You can call `isLoading()` to react to changes in the subscription's loading state. The `isLoading` function will both return the loading state of the subscription, and set up a reactivity for the loading state change. If you don't call this function, no re-render will occur when the loading state changes.
// When a subscription is not used, isLoading() will always return false
261
+
```
262
+
263
+
#### `useFind(cursorFactory, deps)` Accellerate your lists
264
+
265
+
The `useFind` hook can substantially speed up the rendering (and rerendering) of lists coming from mongo queries (subscriptions). It does this by controlling document object references. By providing a highly tailored cursor management within the hook, using the `Cursor.observe` API, `useFind` carefully updates only the object references changed during a DDP update. This approach allows a tighter use of core React tools and philosophies to turbo charge your list renders. It is a very different approach from the more general purpose `useTracker`, and it requires a bit more set up. A notable difference is that you should NOT call `.fetch()`. `useFind` requires its factory to return a `Mongo.Cursor` object. You may also return `null`, if you want to conditionally set up the Cursor.
If you want to conditionally call the find method based on some props configuration or anything else, return `null` from the factory.
297
+
298
+
```jsx
299
+
constdocs=useFind(() => {
300
+
if (props.skip) {
301
+
returnnull
302
+
}
303
+
returnTestDocs.find()
304
+
}, [])
305
+
```
306
+
234
307
### Concurrent Mode, Suspense and Error Boundaries
235
308
236
309
There are some additional considerations to keep in mind when using Concurrent Mode, Suspense and Error Boundaries, as each of these can cause React to cancel and discard (toss) a render, including the result of the first run of your reactive function. One of the things React developers often stress is that we should not create "side-effects" directly in the render method or in functional components. There are a number of good reasons for this, including allowing the React runtime to cancel renders. Limiting the use of side-effects allows features such as concurrent mode, suspense and error boundaries to work deterministically, without leaking memory or creating rogue processes. Care should be taken to avoid side effects in your reactive function for these reasons. (Note: this caution does not apply to Meteor specific side-effects like subscriptions, since those will be automatically cleaned up when `useTracker`'s computation is disposed.)
0 commit comments