12
12
13
13
<br >
14
14
15
- > ** Agent Smith:** ...we have no choice but to continue as planned. Deploy the sentinels. Immediately.
16
-
17
- <!-- ### An Infinite Scroller List Component -->
15
+ > ** Agent Smith:** ...we have no choice but to continue as planned. Deploy the
16
+ > sentinels. Immediately.
18
17
19
18
** React Intersection List** builds on top of
20
- ** [ React Intersection Observer] ( https://github.com/researchgate/react-intersection-observer ) ** , using a
21
- [ sentinel] ( https://en.wikipedia.org/wiki/Sentinel_value ) in the DOM to deliver a high-performance and smooth scrolling
22
- experience, even on low-end devices.
19
+ ** [ React Intersection Observer] ( https://github.com/researchgate/react-intersection-observer ) ** ,
20
+ using a [ sentinel] ( https://en.wikipedia.org/wiki/Sentinel_value ) in the DOM to
21
+ deliver a high-performance and smooth scrolling experience, even on low-end
22
+ devices.
23
+
24
+ <br >
25
+
26
+ <details >
27
+ <summary ><strong >Table of Contents</strong ></summary >
28
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
29
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
30
+
31
+ - [ Getting Started] ( #getting-started )
32
+ - [ Why React Intersection List?] ( #why-react-intersection-list )
33
+ - [ Documentation] ( #documentation )
34
+ - [ How to] ( #how-to )
35
+ - [ FAQ] ( #faq )
36
+ - [ Props] ( #props )
37
+ - [ Examples] ( #examples )
38
+ - [ Contributing] ( #contributing )
39
+
40
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
41
+ </details >
23
42
24
43
## Getting Started
25
44
26
45
```
27
46
$ npm install --save @researchgate/react-intersection-list
28
47
```
29
48
30
- And optionally the [ polyfill] ( https://github.com/w3c/IntersectionObserver/tree/gh-pages/polyfill ) :
49
+ And optionally the
50
+ [ polyfill] ( https://github.com/w3c/IntersectionObserver/tree/gh-pages/polyfill ) :
31
51
32
52
```
33
53
$ npm install --save intersection-observer
34
54
```
35
55
36
- Next create a ` <List> ` and two instance methods as props ` children ` and ` itemRenderer ` :
56
+ Next create a ` <List> ` and two instance methods as props ` children ` and
57
+ ` itemRenderer ` :
37
58
38
59
``` jsx
39
60
import React , { Component } from ' react' ;
40
61
import List from ' @researchgate/react-intersection-list' ;
41
62
42
63
export default class InfiniteList extends Component {
43
- itemsRenderer = (items , ref ) => (
44
- < ul className= " list" ref= {ref}>
45
- {items}
46
- < / ul>
64
+ itemsRenderer = (items , ref ) => (
65
+ < ul className= " list" ref= {ref}>
66
+ {items}
67
+ < / ul>
68
+ );
69
+
70
+ itemRenderer = (index , key ) => < li key= {key}> {index}< / li> ;
71
+
72
+ render () {
73
+ return (
74
+ < List
75
+ itemCount= {1000 }
76
+ itemsRenderer= {this .itemsRenderer }
77
+ renderItem= {this .itemRenderer }
78
+ / >
47
79
);
48
-
49
- itemRenderer = (index , key ) => < li key= {key}> {index}< / li> ;
50
-
51
- render () {
52
- return < List itemCount= {1000 } itemsRenderer= {this .itemsRenderer } renderItem= {this .itemRenderer } / > ;
53
- }
80
+ }
54
81
}
55
82
```
56
83
57
- Note that ` <List> ` is a ` PureComponent ` so it can keep itself from re-rendering. It's highly recommended to avoid
58
- creating new functions for ` renderItem ` and ` itemsRenderer ` so that it can successfully shallow compare props on
59
- re-render.
84
+ Note that ` <List> ` is a ` PureComponent ` so it can keep itself from re-rendering.
85
+ It's highly recommended to avoid creating new functions for ` renderItem ` and
86
+ ` itemsRenderer ` so that it can successfully shallow compare props on re-render.
60
87
61
88
## Why React Intersection List?
62
89
63
- The approach to infinite scrolling was commonly done by devs implementing throttled ` scroll ` event callbacks. This keeps
64
- the main thread unnecessarily busy... No more! ` IntersectionObservers ` invoke callbacks in a ** low-priority and
65
- asynchronous** way by design.
90
+ The approach to infinite scrolling was commonly done by devs implementing
91
+ throttled ` scroll ` event callbacks. This keeps the main thread unnecessarily
92
+ busy... No more! ` IntersectionObservers ` invoke callbacks in a ** low-priority
93
+ and asynchronous** way by design.
66
94
67
95
> ** Agent Smith:** Never send a human to do a machine's job.
68
96
@@ -78,22 +106,27 @@ The implementation follows these steps:
78
106
79
107
### How to
80
108
81
- Provided an ` itemsRenderer ` prop you must attach the ` ref ` argument to your scrollable DOM element:
109
+ Provided an ` itemsRenderer ` prop you must attach the ` ref ` argument to your
110
+ scrollable DOM element:
82
111
83
112
``` jsx
84
- < div ref= {ref}> {items}< / div> ;
113
+ < div ref= {ref}> {items}< / div>
85
114
```
86
115
87
- This element specifies ` overflow: auto|scroll ` and it'll become the ` IntersectionObserver root ` . If the ` overflow `
88
- property isn't found, then ` window ` will be used as the ` root ` instead.
116
+ This element specifies ` overflow: auto|scroll ` and it'll become the
117
+ ` IntersectionObserver root ` . If the ` overflow ` property isn't found, then
118
+ ` window ` will be used as the ` root ` instead.
89
119
90
- The ` sentinel ` element is by default detached from the list when the current size reaches the available length, unless
91
- you're using ` awaitMore ` . In case your list is in memory and you rely on the list for incremental rendering only, the
92
- default detaching behavior suffices. If you're loading more items in an asynchoronous way, make sure you switch
93
- ` awaitMore ` once you reach the total length (bottom of the list).
120
+ The ` sentinel ` element is by default detached from the list when the current
121
+ size reaches the available length, unless you're using ` awaitMore ` . In case your
122
+ list is in memory and you rely on the list for incremental rendering only, the
123
+ default detaching behavior suffices. If you're loading more items in an
124
+ asynchoronous way, make sure you switch ` awaitMore ` once you reach the total
125
+ length (bottom of the list).
94
126
95
- The prop ` itemCount ` must be used if the prop ` items ` is not provided, and viceversa. Calculating the list size is done
96
- by adding the current size and the page size until the items' length is reached.
127
+ The prop ` itemCount ` must be used if the prop ` items ` is not provided, and
128
+ viceversa. Calculating the list size is done by adding the current size and the
129
+ page size until the items' length is reached.
97
130
98
131
### FAQ
99
132
@@ -158,11 +191,13 @@ Find multiple examples under:
158
191
159
192
We'd love your help on creating React Intersection List!
160
193
161
- Before you do, please read our [ Code of Conduct] ( .github/CODE_OF_CONDUCT.md ) so you know what we expect when you
162
- contribute to our projects.
194
+ Before you do, please read our [ Code of Conduct] ( .github/CODE_OF_CONDUCT.md ) so
195
+ you know what we expect when you contribute to our projects.
163
196
164
- Our [ Contributing Guide] ( .github/CONTRIBUTING.md ) tells you about our development process and what we're looking for,
165
- gives you instructions on how to issue bugs and suggest features, and explains how you can build and test your changes.
197
+ Our [ Contributing Guide] ( .github/CONTRIBUTING.md ) tells you about our
198
+ development process and what we're looking for, gives you instructions on how to
199
+ issue bugs and suggest features, and explains how you can build and test your
200
+ changes.
166
201
167
- ** Haven't contributed to an open source project before?** No problem! [ Contributing Guide ] ( .github/CONTRIBUTING.md ) has
168
- you covered as well.
202
+ ** Haven't contributed to an open source project before?** No problem!
203
+ [ Contributing Guide ] ( .github/CONTRIBUTING.md ) has you covered as well.
0 commit comments