Skip to content

Commit 0a648c0

Browse files
committed
docs: readme
1 parent 9de8263 commit 0a648c0

12 files changed

+110
-17
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,138 @@
1+
<h1 align="center">🧻 infinite-scroll-hook (React)</h1>
2+
13
<p align="center">
2-
<img src="logo.png" alt="logo" width="550px" />
4+
<a href="https://github.com/iamyoki/infinite-scroll-hook/actions/workflows/test.yml"><img src="https://github.com/iamyoki/infinite-scroll-hook/actions/workflows/test.yml/badge.svg" alt="πŸ§ͺ Run Tests"></a>
5+
<a href="https://github.com/iamyoki/infinite-scroll-hook/actions/workflows/release.yml"><img src="https://github.com/iamyoki/infinite-scroll-hook/actions/workflows/release.yml/badge.svg" alt="πŸš€ Release The Package"></a>
6+
<a href="https://github.com/iamyoki/infinite-scroll-hook">
7+
<img src="https://img.shields.io/bundlephobia/minzip/infinite-scroll-hook?color=%237B68EE&label=Minizipped%20Size" alt="transition hook">
8+
</a>
9+
<a href="https://github.com/iamyoki/infinite-scroll-hook">
10+
<img src="https://img.shields.io/github/license/iamyoki/infinite-scroll-hook?color=Turquoise" alt="">
11+
</a>
312
</p>
413

5-
<br />
6-
<h1 align="center">🎁 qhlab-library-template</h1>
14+
<br>
15+
<p align="center"><strong>Scroll down to load more never been so easy!</strong></p>
16+
<br>
717

818
<p align="center">
9-
<a href="https://github.com/iamyoki/transition-hook/actions/workflows/test.yml"><img src="https://github.com/iamyoki/transition-hook/actions/workflows/test.yml/badge.svg" alt="πŸ§ͺ Run Tests"></a>
10-
<a href="https://github.com/iamyoki/transition-hook/actions/workflows/release.yml"><img src="https://github.com/iamyoki/transition-hook/actions/workflows/release.yml/badge.svg" alt="πŸš€ Release The Package"></a>
11-
<a href="https://github.com/iamyoki/transition-hook">
12-
<img src="https://img.shields.io/bundlephobia/minzip/transition-hook?color=%237B68EE&label=Minizipped%20Size" alt="transition hook">
13-
</a>
14-
<a href="https://github.com/iamyoki/transition-hook">
15-
<img src="https://img.shields.io/github/license/iamyoki/transition-hook?color=Turquoise" alt="">
19+
<a href="https://codesandbox.io/s/try-infinite-scroll-hook-jo6uxc?file=/src/App.jsx" target="_blank">
20+
<img src="gifs/code.png" alt="example">
1621
</a>
1722
</p>
1823

1924
<br>
20-
<p align="center"><strong>A template make make open-source library never been so easy.</strong></p>
25+
26+
<p align="center">
27+
<a href="https://codesandbox.io/s/try-infinite-scroll-hook-jo6uxc?file=/src/App.jsx">See Example in Codesandbox</a>
28+
</p>
29+
2130
<br>
2231

2332
- [Installation](#installation)
2433
- [Usage](#usage)
34+
- [Simple usage](#simple-usage)
35+
- [Offset](#offset)
36+
- [Stop load more](#stop-load-more)
2537
- [API Reference](#api-reference)
2638
- [License](#license)
2739

40+
<br>
41+
2842
## Installation
2943

3044
Install with yarn
3145

3246
```bash
33-
yarn add qhlab-library-template
47+
yarn add infinite-scroll-hook
3448
```
3549

3650
Or install with npm
3751

3852
```bash
39-
npm install qhlab-library-template --save
53+
npm install infinite-scroll-hook --save
4054
```
4155

4256
## Usage
4357

44-
> Write some thing nice.
58+
### Simple usage
59+
60+
```jsx
61+
export default function App() {
62+
const [list, setList] = useState([...Array(11).keys()])
63+
const { containerRef, isLoading } = useInfiniteScroll({
64+
async onLoadMore() {
65+
const res = await fetchList(list.slice(-1)[0])
66+
setList(list.concat(res))
67+
},
68+
})
69+
70+
return (
71+
<div className="App">
72+
<List ref={containerRef}>
73+
{list.map((n) => (
74+
<Item key={n}>{n}</Item>
75+
))}
76+
{isLoading && <Loading>Loading ...</Loading>}
77+
</List>
78+
</div>
79+
)
80+
81+
```
82+
83+
### Offset
84+
85+
Will load more while scrolling hit to bottom offset '200px'
86+
87+
```jsx
88+
const { containerRef, isLoading } = useInfiniteScroll({offset: '200px'})
89+
...
90+
```
91+
92+
All css size units available
93+
94+
- `offset: 200px` βœ…
95+
- `offset: 20%` βœ…
96+
- `offset: 20vh` βœ…
97+
- `offset: 20cm` βœ…
98+
- ...
99+
100+
### Stop load more
101+
102+
Stops when finished
103+
104+
```jsx
105+
const { containerRef, isLoading } = useInfiniteScroll({shouldStop: isFetchEnd})
106+
...
107+
108+
return (
109+
<div className="App">
110+
<List ref={containerRef}>
111+
{list.map((n) => (
112+
<Item key={n}>{n}</Item>
113+
))}
114+
{(isLoading || !isFetchEnd) && <Loading>Loading ...</Loading>}
115+
</List>
116+
</div>
117+
)
118+
```
45119
46120
## API Reference
47121
48-
> Write some thing nice.
122+
```js
123+
const {containerRef, isLoading} = useTransition(options)
124+
```
125+
126+
| Parameters | Type | Description |
127+
| :--------- | :---------------------------------------------------------------------------- | :------------------------ |
128+
| `options` | `{ offset?: string; shouldStop?: boolean; onLoadMore?: () => Promise<void> }` | This is the option object |
129+
130+
<br>
131+
132+
| Returns | Type | Description |
133+
| :------------- | :----------------------- | :-------------------------------------------------- |
134+
| `containerRef` | `LegacyRef<HTMLElement>` | The ref object attach to your jsx container element |
135+
| `isLoading` | `boolean` | Whether is loading or not |
49136
50137
## License
51138
-524 KB
Binary file not shown.

β€Žgifs/basic.gifβ€Ž

-692 KB
Binary file not shown.

β€Žgifs/code.pngβ€Ž

428 KB
Loading
-550 KB
Binary file not shown.

β€Žgifs/emoji-transition.gifβ€Ž

-387 KB
Binary file not shown.

β€Žgifs/example.gifβ€Ž

1.06 MB
Loading

β€Žgifs/painter.gifβ€Ž

-646 KB
Binary file not shown.

β€Žgifs/radio-transition.gifβ€Ž

-461 KB
Binary file not shown.

β€Žgifs/ripple-effect.gifβ€Ž

-573 KB
Binary file not shown.

0 commit comments

Comments
Β (0)