Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/react-meteor-data/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## v4.0.0-beta.0, xxx
* Breaking change: useFind describes no deps by default [PR#431](https://github.com/meteor/react-packages/pull/431)
* Fix concurrency issue with useFind [PR#419](https://github.com/meteor/react-packages/pull/419)
* Improve `useFind` and `useSubscribe` React suspense hooks [PR#420](https://github.com/meteor/react-packages/pull/429), [PR#430](https://github.com/meteor/react-packages/pull/430) and [PR#441](https://github.com/meteor/react-packages/pull/441)

## v3.0.3, 2024-12-30
* Add `useSubscribeSuspenseServer` hook to be used in SSR.

Expand Down
2 changes: 1 addition & 1 deletion packages/react-meteor-data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Package.onUse((api) => {
api.use('tracker')
api.use('ecmascript')
api.use('typescript')
api.use('zodern:[email protected]', 'server')
api.use('zodern:[email protected]')

api.mainModule('index.ts', ['client', 'server'], { lazy: true })
})
Expand Down
35 changes: 17 additions & 18 deletions packages/react-meteor-data/useFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,23 @@ const fetchData = <T>(cursor: Mongo.Cursor<T>) => {
}

const useSyncEffect = (effect, deps) => {
const [cleanup, timeoutId] = useMemo(
() => {
const cleanup = effect();
const timeoutId = setTimeout(cleanup, 1000);
return [cleanup, timeoutId];
},
deps
);

useEffect(() => {
clearTimeout(timeoutId);

return cleanup;
}, [cleanup]);
};


const useFindClient = <T = any>(factory: () => (Mongo.Cursor<T> | undefined | null), deps: DependencyList = []) => {
const [cleanup, timeoutId] = useMemo(
() => {
const cleanup = effect();
const timeoutId = setTimeout(cleanup, 1000);
return [cleanup, timeoutId];
},
deps
);

useEffect(() => {
clearTimeout(timeoutId);

return cleanup;
}, [cleanup]);
};

const useFindClient = <T = any>(factory: () => (Mongo.Cursor<T> | undefined | null), deps: DependencyList) => {
const cursor = useMemo(() => {
// To avoid creating side effects in render, opt out
// of Tracker integration altogether.
Expand Down