{"id":19747023,"url":"https://github.com/phphe/react-base-virtual-list","last_synced_at":"2025-04-30T08:32:08.203Z","repository":{"id":220818848,"uuid":"752701377","full_name":"phphe/react-base-virtual-list","owner":"phphe","description":"React basic virtual list. Easy to customize. 基础虚拟列表，易于二次开发。","archived":false,"fork":false,"pushed_at":"2024-03-07T14:12:03.000Z","size":208,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-09T13:42:02.954Z","etag":null,"topics":["react","virtual-list"],"latest_commit_sha":null,"homepage":"https://phphe.github.io/react-base-virtual-list/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phphe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-04T15:16:16.000Z","updated_at":"2024-11-02T15:11:20.000Z","dependencies_parsed_at":"2024-10-30T01:03:40.288Z","dependency_job_id":null,"html_url":"https://github.com/phphe/react-base-virtual-list","commit_stats":{"total_commits":80,"total_committers":1,"mean_commits":80.0,"dds":0.0,"last_synced_commit":"92f93285ae942dcdaec35425b19aba0c3688af0d"},"previous_names":["phphe/react-base-virtual-list"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphe%2Freact-base-virtual-list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphe%2Freact-base-virtual-list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphe%2Freact-base-virtual-list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphe%2Freact-base-virtual-list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phphe","download_url":"https://codeload.github.com/phphe/react-base-virtual-list/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224202754,"owners_count":17272807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","virtual-list"],"created_at":"2024-11-12T02:16:41.194Z","updated_at":"2024-11-12T02:16:41.826Z","avatar_url":"https://github.com/phphe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-base-virtual-list ![GitHub License](https://img.shields.io/github/license/phphe/react-base-virtual-list) ![NPM Version](https://img.shields.io/npm/v/react-base-virtual-list) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/phphe/react-base-virtual-list/build.yml) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-base-virtual-list)\n\n[中文](README_CN.md)\n\nReact basic virtual list, supports common features and is easy to customize. [Online Demo](https://phphe.github.io/react-base-virtual-list/)\n\n## Features\n\n- Supports common features and is easy to customize. Check [Development](#development).\n- Supports lists with fixed height or dynamic height items.\n- High performance. For lists with different item heights, it does not retrieve the height of each item.\n- Formats of exported files: typescript, cjs, esm, iife, iife source map. iife can be use by `script` tag in browser, see [IIFE](#iife).\n\n## Installation\n\n- npm: `npm install react-base-virtual-list`\n- yarn: `yarn add react-base-virtual-list`\n- pnpm: `pnpm add react-base-virtual-list`\n- CDN: Check [iife](#iife).\n\n## Usage\n\n```tsx\nimport { VirtualList } from \"react-base-virtual-list\";\n\nexport default function BaseExample() {\n  const exampleData = [\n    {\n      headline: \"in magna bibendum imperdiet\",\n      content: \"Praesent blandit. Nam nulla.\",\n    },\n    {\n      headline: \"non velit donec diam\",\n      content: \"Aenean fermentum.\",\n    },\n  ];\n  return (\n    \u003c\u003e\n      \u003cVirtualList\n        items={exampleData}\n        style={{ height: \"600px\", border: \"1px solid #ccc\", padding: \"10px\" }}\n        renderItem={(item, index) =\u003e (\n          \u003cdiv key={index} style={{ marginBottom: \"10px\" }}\u003e\n            \u003ch3\u003e\n              {index}. {item.headline}\n            \u003c/h3\u003e\n            \u003cdiv\u003e\n              \u003cdiv\n                style={{\n                  float: \"left\",\n                  width: \"100px\",\n                  height: \"100px\",\n                  background: \"#f0f0f0\",\n                  borderRadius: \"5px\",\n                  marginRight: \"10px\",\n                }}\n              \u003e\u003c/div\u003e\n              {item.content}\n            \u003c/div\u003e\n          \u003c/div\u003e\n        )}\n      \u003e\u003c/VirtualList\u003e\n    \u003c/\u003e\n  );\n}\n```\n\n## props (required)\n\n- `items`: `Array`. List data.\n- `renderItem`: `(item, index: number) =\u003e ReactNode`. Rendering function for each item in the list. Index is the index of the list item in the whole list.\n\n## props (optional)\n\n- `itemSize`: `number`. Estimated height of a single item in the list.\n- `buffer`: `number`. Additional space outside the visible area of the virtual list to render.\n- `persistentIndices`: `number[]`. Array of indices of items to be persistently rendered. This keeps the corresponding items rendered continuously without being removed due to being outside the rendering area. You can make them sticky by using CSS `position:sticky`.\n- `listSize`: `number`, default: 1000. Height of the visible area of the list. Only used before DOM creation, suitable for SSR.\n- `triggerDistance`: `number`. The min distance to trigger re-rendering when scrolling.\n- `onScroll`: `React.UIEventHandler`. Listen for the list's scroll event. Type is same with HTML native onscroll handle.\n- `virtual`: `boolean`. default: `true`. Whether to enable the virtual list feature. Render all items if disabled.\n- `renderHead`: `() =\u003e ReactNode`. Customize the persistent rendering content of the list header. Suitable for absolutely positioned, fixed positioned elements, and elements that do not take up too much space.\n- `renderFoot`: `() =\u003e ReactNode`. Customize the persistent rendering content of the list footer. Suitable for absolutely positioned, fixed positioned elements, and elements that do not take up too much space.\n- `className`: `string`. Add a CSS class to the list root element.\n- `style`: `React.CSSProperties`. Add CSS styles to the list root element.\n\n## Exposed Methods\n\nFirst, use `ref` to obtain the exposed object.\n\n```tsx\nimport { useRef } from \"react\";\nimport { VirtualList, VirtualListHandle } from \"react-base-virtual-list\";\n\nexport default function BaseExample() {\n  const ref = useRef\u003cVirtualListHandle\u003e(null);\n  return (\n    \u003c\u003e\n      \u003cVirtualList ref={ref}\u003e\u003c/VirtualList\u003e\n    \u003c/\u003e\n  );\n}\n```\n\nIrrelevant parts are omitted in the above code. `VirtualListHandle` is a `typescript` type, please ignore it if you are using pure JS.\n\n`VirtualListHandle` type code.\n\n```ts\ninterface VirtualListHandle {\n  scrollToIndex(\n    index: number,\n    block?: \"start\" | \"end\" | \"center\" | \"nearest\"\n  ): void;\n  getRootElement(): HTMLElement;\n  forceUpdate(): void;\n}\n```\n\nThen use the `ref` object to access the exposed methods.\n\n- `scrollToIndex`: `(index:number, block = 'start'):void`. Scroll to the specified index position. `block` is equal to the `block` option of the HTML native method `scrollIntoView`.\n- `getRootElement`: Get list HTML element。\n- `forceUpdate`: Forcefully re-render the list. This can be called after the visible area of the list changes.\n\n## Note\n\n- Remember to set the height of the list. Class, style, px, em, percentage, etc. are all acceptable.\n- Delayed loading, loading when scrolling to the bottom, etc. can be implemented using the exposed `onScroll`.\n\n## IIFE\n\nThe `dist/index.iife.js` file can be run in the browser.\nYou can host it on your server and then use the `script` tag to include it. Before including it, you also need to include `react`, `react-dom`. The global variable exposed by this file is `reactBaseVirtualList`, you can access all the exports of this file through `window.reactBaseVirtualList`, and get the main component exported through `window.reactBaseVirtualList.VirtualList`.\n\nYou can also use the following third-party CDN url to include it.\n\n- unpkg: https://unpkg.com/react-base-virtual-list\n- jsdelivr: https://cdn.jsdelivr.net/npm/react-base-virtual-list\n\n## Development\n\n- `lib`: The main files, also the files that are packaged into the library. Running `npm run build` will package the files in this directory into the `dist` folder. The corresponding Vite configuration file is `vite.build.ts`.\n- `src`: The files used for development and debugging. Running `npm run dev` will run the code in this directory in the browser. Running `npm run build:web` will package the code in this directory into the `dist` folder. The corresponding Vite configuration file is `vite.config.ts`.\n- `uno.config.ts`: [unocss](https://github.com/unocss/unocss) configuration file. `unocss` only works in the `src` folder. With the current configuration, you can use `Tailwindcss` style class names.\n- `.github/workflows/build.yml`: Some automated actions performed when publishing to GitHub. You can delete or modify it.\n\n## Changelog\n\nhttps://github.com/phphe/react-base-virtual-list/releases\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphphe%2Freact-base-virtual-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphphe%2Freact-base-virtual-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphphe%2Freact-base-virtual-list/lists"}