Skip to content

Commit 7fe392c

Browse files
RendezLuis Merino
authored andcommitted
chore(readme): added more docs and FAQ section
1 parent ca7bebd commit 7fe392c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Before you start your work, make sure that you:
4242

4343
### How to run the project
4444

45-
Install React Intersection List as a global npm package:
45+
Create a clone of the repository:
4646

4747
```
4848
git clone https://github.com/researchgate/react-intersection-list.git

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ The implementation follows these steps:
6767

6868
## Documentation
6969

70+
### How to
71+
72+
Provided an `itemsRenderer` prop you must attach the `ref` argument to your scrollable DOM element:
73+
74+
```jsx
75+
<div ref={ref}>{items}</div>
76+
```
77+
78+
This element specifies `overflow: auto|scroll` and it'll become the `IntersectionObserver root`. If the `overflow` property isn't found, then `window` will be used as the `root` instead.
79+
80+
The `<sentinel />` element is by default detached from the list when the current size reaches the available length, unless you're using `awaitMore`. In case your list is in memory and you rely on the list for incremental rendering only, the default detaching behavior suffices. If you're loading items asynchoronously on-demand, make sure to switch `awaitMore` once you reach the total `itemsLength`.
81+
82+
### FAQ
83+
84+
Q: Why am I receiving too many `onIntersection` callbacks
85+
86+
We extend `React.PureComponent`, so IF the parent component re-renders, and the _props_ passed to your `<List />` don't hold the same reference anymore, the list re-renders and may accidentally be re-attaching the `<sentinel />`.
87+
88+
Q: Do I always need to assign the `ref`?
89+
90+
Yes, this callback is used to start up the `IntersectionObserver`.
91+
92+
Q: What's the `threshold` value, and why does it need an _unit_?
93+
94+
The `threshold` value is the amount of space needed before the `<sentinel />` intersects with the root. The prop transformed into a valid `rootMargin` property for the `IntersectionObserver`, depending on the `axis` you select. As a sidenote, we believe that a percentage unit works best for responsive layouts.
95+
96+
Q: I am getting a console warning when I first load the list
97+
98+
> The sentinel detected a viewport with a bigger size than the size of its items...
99+
100+
The prop `pageSize` is `10` by default, so make sure you're not falling short on items when you first render the component. The idea of an infinite scrolling list is that items overflow the viewport, so that users have the impression that there're always more items available.
101+
70102
### Options
71103

72104
- **children**: `(index: number, key: number) => React.Element<*>`

0 commit comments

Comments
 (0)