mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: cashflow account transactions infinity scroll loading.
This commit is contained in:
@@ -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';
|
||||
36
src/hooks/utils/useIntersectionObserver.js
Normal file
36
src/hooks/utils/useIntersectionObserver.js
Normal 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]);
|
||||
}
|
||||
Reference in New Issue
Block a user