MCPcopy Create free account
hub / github.com/Free-APIs/Free-APIs.github.io / ListDisplay

Function ListDisplay

src/components/ListDisplay/index.js:6–119  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

4import OptionsRow from './OptionsRow';
5
6function ListDisplay(props) {
7 let listItems = props.children;
8 const [display, setDisplay] = useState([]);
9
10 useEffect(() => {
11 if (listItems) {
12 setDisplay(listItems.slice(0, 15));
13 }
14 }, [listItems]);
15
16 const observer = useRef();
17 const lastElementRef = useCallback(
18 (node) => {
19 if (!display) return;
20 if (observer.current) observer.current.disconnect();
21 observer.current = new IntersectionObserver((entries) => {
22 if (entries[0].isIntersecting) {
23 if (display.length + 15 < listItems.length) {
24 setDisplay(
25 display.concat(
26 listItems.slice(
27 display.length,
28 display.length + 15,
29 ),
30 ),
31 );
32 } else {
33 setDisplay(listItems);
34 }
35 }
36 });
37 if (node) observer.current.observe(node);
38 },
39 [display, listItems],
40 );
41
42 const header = (categoryTitle) => (
43 <div className='w-full flex'>
44 <div
45 className='mx-auto mb-4 mt-6 p-4 rounded-lg shadow-lg
46 bg-gray-700 sm:text-xl lg:text-2xl xl:text-3xl text-gray-100
47 flex-none'
48 >
49 {categoryTitle}
50 </div>
51 </div>
52 );
53
54 const output = () => {
55 if (props.isCategory) {
56 listItems.sort((a, b) =>
57 a['Category'].localeCompare(b['Category']),
58 );
59 }
60
61 let previous = null;
62
63 return (

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected