Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #ListFinally
  2. import React, { useState } from "react";
  3. import InfiniteScroll from "react-infinite-scroll-component";
  4. import "./App.css";
  5. import { people } from "./people";
  6.  
  7. export const ListFinally = () => {
  8. const [items, setItems] = useState(people.slice(0, 3));
  9. let num = 5;
  10. const [hasMore, setHasMore] = useState(true);
  11. const fetchMoreData = () => {
  12. if (items.length >= 500) {
  13. setHasMore(false);
  14. return;
  15. }
  16. // a fake async api call like which sends
  17. // 20 more records in .5 secs
  18. num = items.length + 2;
  19. setTimeout(() => {
  20. setItems(people.slice(0, num));
  21. }, 500);
  22. };
  23.  
  24. return (
  25. <div>
  26. <InfiniteScroll
  27. dataLength={items.length}
  28. next={fetchMoreData}
  29. hasMore={hasMore}
  30. loader={<h4>Ładowanie...</h4>}
  31. >
  32. {items.map(({ name, email, city, mac, timestamp, creditcard }) => (
  33. <ul>
  34. <li>{name}</li>
  35. <li>{email}</li>
  36. <li>{city}</li>
  37. <li>{mac}</li>
  38. <li>{timestamp}</li>
  39. <li>{creditcard}</li>
  40. </ul>
  41. ))}
  42. </InfiniteScroll>
  43. </div>
  44. );
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement