Skip to content

Commit c6a3209

Browse files
committed
(#6140) Review changes
1 parent 360597e commit c6a3209

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

dev/src/components/docs/ComponentList.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ type Props = Language & {
1515

1616
const LazyLoadComponent: FC<Component & Language & {
1717
path?: string
18-
}> = ({ name, lang, path, loadComponent }) => {
18+
observer: (cb: () => void) => IntersectionObserver;
19+
}> = ({ name, lang, path, loadComponent, observer }) => {
1920
const history = useHistory();
2021
const ref = useRef<HTMLDivElement>(null);
2122
const [isVisible, setIsVisible] = useState<boolean>(false);
2223

2324
useEffect(() => {
24-
const observer = new IntersectionObserver((entries) => {
25-
entries.forEach((entry) => {
26-
if (entry.isIntersecting) {
27-
setIsVisible(true);
28-
}
29-
})
30-
});
31-
observer.observe(ref.current as Element);
32-
}, []);
25+
observer(() => setIsVisible(true)).observe(ref.current as Element);
26+
}, [observer]);
3327

3428
const formattedComponentName = name.charAt(0).toUpperCase() + name.slice(1);
3529

@@ -73,12 +67,19 @@ export const ComponentList: FC<Props> = ({ lang }) => {
7367
if (components?.length <= 0) return null
7468
const componentLength = components.length
7569
const headline = lang === "de" ? `Anzahl Komponenten: ${componentLength}` : `Components sum: ${componentLength}`
70+
const observer = useCallback((cb: () => void) => new IntersectionObserver((entries) => {
71+
entries.forEach((entry) => {
72+
if (entry.isIntersecting) {
73+
cb()
74+
}
75+
})
76+
}), []);
7677
return (
7778
<>
7879
<KolHeading _label={headline} _level={3}>{headline}</KolHeading>
7980
<div className="components-overview">
8081
{components.map(({ name, loadComponent }) => (
81-
<LazyLoadComponent key={name} name={name} lang={lang} path={preferredVersion?.path} loadComponent={loadComponent} />
82+
<LazyLoadComponent key={name} name={name} lang={lang} path={preferredVersion?.path} loadComponent={loadComponent} observer={observer} />
8283
))}
8384
</div>
8485
</>

0 commit comments

Comments
 (0)