본문으로 건너뛰기

Example

import { ViewPortRenderList } from "./lib";
import { useEffect, useState } from "react";

export default function App() {
const [list, setList] = useState([]);
useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/photos")
.then((res) => res.json())
.then((res) => {
setList(res);
});
}, []);
return (
<div>
<ViewPortRenderList
render={(index) => (
<div>
<h5>{list[index].title}</h5>
<img src={list[index].thumbnailUrl} alt="" />
</div>
)}
totalCount={list.length}
rowHeight={193}
/>
</div>
);
}

Note

  • render, totalCount, rowHeight are required.
  • render is a function that returns a component to be rendered.
  • totalCount is the total number of items to be rendered.
  • rowHeight is the height of each item(Don't care about extra height, it will be automatically calculated).
  • rowGap is the gap between each item. (default: 0)
  • paddingCount is the number of items to be rendered in advance. (default: 0)
warning
  • startMargin is the start position of the list. (default: 0). If you has a header, navbar, etc, you must to set the height all of them to startMargin. You need to calculate the height of all of them.