UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

26 lines (25 loc) 1.31 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from 'react'; import InfiniteScroll from '../index'; const style = { height: 30, border: '1px solid green', margin: 6, padding: 8 }; export default function InfiniteScrollWithHeight() { const [hasMore, setHasMore] = useState(true); const [items, setItems] = useState(Array.from({ length: 20 })); const fetchMoreData = () => { if (items.length >= 500) { setHasMore(false); return; } // a fake async api call like which sends // 20 more records in .5 secs setTimeout(() => { setItems(items.concat(Array.from({ length: 20 }))); }, 500); }; return (_jsxs("div", { children: [_jsx("h1", { children: "demo: Infinite Scroll with fixed height" }), _jsx("hr", {}), _jsx(InfiniteScroll, Object.assign({ dataLength: items.length, next: fetchMoreData, hasMoreNext: hasMore, loaderNext: _jsx("h4", { children: "Loading..." }), height: 400, endMessage: _jsx("p", Object.assign({ style: { textAlign: 'center' } }, { children: _jsx("b", { children: "Yay! You have seen it all" }) })) }, { children: items.map((_, index) => (_jsxs("div", Object.assign({ style: style }, { children: ["div - #", index] }), index))) }))] })); }