feat: cashflow account transactions infinity scroll loading.

This commit is contained in:
a.bouhuolia
2021-10-23 23:10:48 +02:00
parent c7013caf12
commit 65e8d3f26a
11 changed files with 268 additions and 68 deletions

View File

@@ -6,4 +6,5 @@ export * from './useUpdateEffect';
export * from './useWatch';
export * from './useWhen';
export * from './useRequestPdf';
export * from './useAsync';
export * from './useAsync';
export * from './useIntersectionObserver';

View File

@@ -0,0 +1,36 @@
import React from 'react';
export function useIntersectionObserver({
root,
target,
onIntersect,
threshold = 1.0,
rootMargin = '0px',
enabled = true,
}) {
React.useEffect(() => {
if (!enabled) {
return;
}
const observer = new IntersectionObserver(
(entries) =>
entries.forEach((entry) => entry.isIntersecting && onIntersect()),
{
root: root && root.current,
rootMargin,
// threshold,
threshold: 0.25,
},
);
const el = target && target.current;
if (!el) {
return;
}
observer.observe(el);
return () => {
observer.unobserve(el);
};
}, [target.current, enabled, onIntersect, root]);
}