Skip to content

Commit 3b26905

Browse files
committed
feat(*): initial version
0 parents  commit 3b26905

26 files changed

+24248
-0
lines changed

.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"modules": false
7+
}
8+
],
9+
"@babel/react"
10+
]
11+
}

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": ["prettier", "prettier/react"],
4+
"env": {
5+
"es6": true
6+
},
7+
"plugins": ["prettier", "react", "react-hooks"],
8+
"parserOptions": {
9+
"sourceType": "module"
10+
}
11+
}

.github/workflows/npmpublish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
- run: yarn
16+
- run: yarn test
17+
18+
publish-npm:
19+
needs: build
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v1
23+
- uses: actions/setup-node@v1
24+
with:
25+
node-version: 12
26+
registry-url: https://registry.npmjs.org/
27+
- run: yarn
28+
- run: npm publish
29+
env:
30+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# See https://help.github.com/ignore-files/ for more about ignoring files.
3+
4+
# dependencies
5+
node_modules
6+
7+
# builds
8+
build
9+
dist
10+
.rpt2_cache
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*

.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git
2+
yarn.lock
3+
rollup*
4+
.eslint*
5+
.babelrc
6+
.prettierrc
7+
.gitignore
8+
src
9+
example

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# use-infinite-scroll
2+
3+
[![NPM](https://img.shields.io/npm/v/closeio_use-infinite-scroll.svg)](https://www.npmjs.com/package/use-infinite-scroll) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-success)](https://prettier.io)
4+
5+
Super simple React hook for creating an infinite scroll experience based on the `IntersectionObserver` API.
6+
7+
[Check the live DEMO](https://closeio.github.io/use-infinite-scroll/).
8+
9+
### <img height="40px" src="./close.svg" />
10+
11+
Interested in working on projects like this? [Close](https://close.com) is looking for [great engineers](https://jobs.close.com) to join our team!
12+
13+
## Install
14+
15+
```bash
16+
yarn add @closeio/use-infinite-scroll
17+
```
18+
19+
## Benefits
20+
21+
- Extremely lightweight (less than 1KB minzipped).
22+
- It uses the `IntersectionObserver` API, so it doesn't need to listen to `scroll` events – which are known to cause performance issues.
23+
- No other 3rd-party dependencies.
24+
25+
## Usage
26+
27+
```jsx
28+
import React from 'react';
29+
import useInfiniteScroll from '@closeio/use-infinite-scroll';
30+
31+
const [items, setItems] = useState([]);
32+
const [hasMore, setHasMore] = useState(false);
33+
const [page, loaderRef, scrollerRef] = useInfiniteScroll({ hasMore });
34+
35+
useEffect(async () => {
36+
const data = await myApiCall({ page });
37+
setHasMore(data.hasMore);
38+
setItems(prev => [...prev, data.items]);
39+
}, [page]);
40+
41+
return (
42+
<div ref={scrollerRef}>
43+
{items.map(item => (
44+
<div key={item.id}>{item.name}</div>
45+
))}
46+
{hasMore && <div ref={loaderRef}>Loading…</div>}
47+
</div>
48+
);
49+
```
50+
51+
## License
52+
53+
MIT © [Close](https://github.com/closeio)

close.svg

Lines changed: 28 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)