├── .babelrc
├── .eslintrc.json
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── build
├── asset-manifest.json
├── favicon.ico
├── index.html
├── manifest.json
├── service-worker.js
└── static
│ └── js
│ ├── runtime~main.fdfcfda2.js
│ └── runtime~main.fdfcfda2.js.map
├── dist
└── index.js
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
├── rollup.config.js
├── src
├── App.jsx
├── InfiniteList.jsx
├── InfiniteList.test.jsx
├── index.jsx
└── mock_data.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["@babel/preset-env", "@babel/preset-react"]
3 | }
4 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "es6": true,
5 | "jest": true
6 | },
7 | "extends": ["eslint:recommended", "plugin:react/recommended"],
8 | "globals": {
9 | "Atomics": "readonly",
10 | "SharedArrayBuffer": "readonly"
11 | },
12 | "parserOptions": {
13 | "ecmaFeatures": {
14 | "jsx": true
15 | },
16 | "ecmaVersion": 2018,
17 | "sourceType": "module"
18 | },
19 | "plugins": ["react", "react-hooks"],
20 | "rules": {
21 | "react-hooks/rules-of-hooks": "error",
22 | "react-hooks/exhaustive-deps": "warn"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 | public
3 | build
4 | .babelrc
5 | rollup.config.js
6 | .eslintrc.json
7 | yarn.lock
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-infinite-list
2 |
3 | A handy React component to render infinite, onScroll fetched, data lists.
4 |
5 | Demo: https://react-infinite-list.netlify.com
6 |
7 | 
8 | 
9 |
10 | ---
11 |
12 | ### Install
13 |
14 | ```sh
15 | $ npm install @damnhotuser/react-infinite-list
16 | ```
17 |
18 | ---
19 |
20 | ### Usage
21 |
22 | `react-infinite-list` provides a single component, `InfiniteList`.
23 |
24 | ```jsx
25 | import React, { useState } from "react";
26 |
27 | import InfiniteList from "@damnhotuser/react-infinite-list";
28 | import mock_fetch from "./mock_data"; // mocking an API service
29 |
30 | const App = props => {
31 | const [rows, setRows] = useState([]);
32 |
33 | const fetchData = (offset, limit) =>
34 | mock_fetch(offset, limit).then(data => {
35 | setRows([...rows, ...data]);
36 | });
37 |
38 | return (
39 | /*
40 | * InfiniteList takes three needed arguments:
41 | * `rows` are data to display in the list
42 | * `fetchData` is called on rendering and when needed, on scroll
43 | * `limit` is the number of rows to fetch on each `fetchData` call
44 | *
45 | * InfiniteList's `children` must be a function, and has the row to render passed as an argument
46 | *
47 | * current `index` and `ref` will also be passed as arguments of your `children` function, it is IMPORTANT to pass ref to the rendered list element for the onScroll fetch to work
48 | */
49 |
50 | {(row, index, ref) => (
51 |
52 | {row.name}
53 |
54 | )}
55 |
56 | );
57 | };
58 | ```
59 |
60 |
61 |
62 | **⚠️ InfiniteList's `children` must be a function. The current row to render will be passed as an argument.**
63 |
64 | **⚠️ current `index` and `ref` will also be passed as arguments of your `children` function, it is IMPORTANT to pass ref to the rendered list element for the onScroll fetch to work**
65 |
66 |
67 |
68 | `InfiniteList` takes also 3 optionnal arguments:
69 |
70 | - `containerClasses` are classes that will be passed as an argument to the `div` holding your list.
71 | - `containerStyle` are style rules that will be passed as an argument to the `div` holding your list.
72 | - `fetchThreshold` (number) is the number of element before the end of the displayed list to wait before calling `fetchData` again. i.e. if n elements are displayed on the list, and `fetchThreshold` is set to 3,`fetchData` will be called when the n-3th element of the list is scrolled into view. **The default value of `fetchthreshold` is 5**.
73 |
--------------------------------------------------------------------------------
/build/asset-manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "main.js": "/static/js/main.869cced1.chunk.js",
3 | "main.js.map": "/static/js/main.869cced1.chunk.js.map",
4 | "runtime~main.js": "/static/js/runtime~main.fdfcfda2.js",
5 | "runtime~main.js.map": "/static/js/runtime~main.fdfcfda2.js.map",
6 | "static/js/2.48d1e2ad.chunk.js": "/static/js/2.48d1e2ad.chunk.js",
7 | "static/js/2.48d1e2ad.chunk.js.map": "/static/js/2.48d1e2ad.chunk.js.map",
8 | "index.html": "/index.html",
9 | "precache-manifest.14377052761068e1c0ccbd5088347daa.js": "/precache-manifest.14377052761068e1c0ccbd5088347daa.js",
10 | "service-worker.js": "/service-worker.js"
11 | }
--------------------------------------------------------------------------------
/build/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mdubourg001/react-infinite-list/a8328a13a84c62dcfe3f35649cc8904a5307bc59/build/favicon.ico
--------------------------------------------------------------------------------
/build/index.html:
--------------------------------------------------------------------------------
1 |