@raf-query/react 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +50 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.8](https://github.com/KATT/raf-query/compare/0.1.7...0.1.8) (2026-10-13)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **examples:** infinite scroll, root dev scripts, readable request names; README and tests cover pagination and infinite scroll ([#37](https://github.com/KATT/raf-query/issues/37)) ([2c3bed6](https://github.com/KATT/raf-query/commit/2c3bed630fd08d0a59686a6f5f14aecba1ff2e1b))
|
|
8
|
+
|
|
3
9
|
## [0.1.7](https://github.com/KATT/raf-query/compare/0.1.6...0.1.7) (2026-10-13)
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
- validate search params with a zod schema in the README ([#36](https://github.com/KATT/raf-query/issues/36)) ([9142236](https://github.com/KATT/raf-query/commit/9142236f611deb0fdf9db5f7e2847bccad89e841))
|
|
6
12
|
|
|
7
13
|
## [0.1.6](https://github.com/KATT/raf-query/compare/0.1.5...0.1.6) (2026-10-12)
|
|
8
14
|
|
package/README.md
CHANGED
|
@@ -273,6 +273,56 @@ Paging controls: `fetchNextPage()`, `fetchPreviousPage()`, `hasNextPage`, `hasPr
|
|
|
273
273
|
|
|
274
274
|
On the server, `ensure` and `fetch` load the first page. Pass `{ pages: n }` as a third argument to load more up front; the option is only accepted for paged factories.
|
|
275
275
|
|
|
276
|
+
### Infinite scroll
|
|
277
|
+
|
|
278
|
+
Infinite scroll is the same paged query with an automatic "Load more". A ref callback watches the button and presses it when it nears the viewport. Unmount the button while a page loads: it watches again when it remounts, so it keeps loading while it stays in reach. Its place is taken by skeletons the size of the incoming page, so the loaded rows replace them without moving anything below.
|
|
279
|
+
|
|
280
|
+
```tsx
|
|
281
|
+
function Comments(props: { handle: QueryHandle<typeof commentsQuery> }) {
|
|
282
|
+
const [pagesPromise, comments] = useQuery(commentsQuery, props.handle);
|
|
283
|
+
const data = use(pagesPromise);
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<>
|
|
287
|
+
{data.pages
|
|
288
|
+
.flatMap((page) => page.items)
|
|
289
|
+
.map((comment) => (
|
|
290
|
+
<Comment key={comment.id} {...comment} />
|
|
291
|
+
))}
|
|
292
|
+
{comments.isFetchingNextPage ? <CommentSkeletons /> : null}
|
|
293
|
+
{comments.hasNextPage && !comments.isFetchingNextPage ? (
|
|
294
|
+
<button
|
|
295
|
+
onClick={() => comments.fetchNextPage()}
|
|
296
|
+
ref={(button) => {
|
|
297
|
+
if (button === null) return;
|
|
298
|
+
const observer = new IntersectionObserver(
|
|
299
|
+
(entries) => {
|
|
300
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
301
|
+
observer.disconnect();
|
|
302
|
+
comments.fetchNextPage();
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
{ rootMargin: "0px 0px 300px 0px" },
|
|
306
|
+
);
|
|
307
|
+
observer.observe(button);
|
|
308
|
+
return () => observer.disconnect();
|
|
309
|
+
}}
|
|
310
|
+
>
|
|
311
|
+
Load more
|
|
312
|
+
</button>
|
|
313
|
+
) : null}
|
|
314
|
+
</>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Pagination and infinite scroll differ in where the page lives:
|
|
320
|
+
|
|
321
|
+
- **Pagination**: the page is a search param and part of the input, so each page is its own query and the URL links to it ([below](#when-the-url-changes)).
|
|
322
|
+
- **Infinite scroll**: filters and sort are search params, and pages are loaded into one paged query per input. Changing a filter starts a new list from its first page.
|
|
323
|
+
|
|
324
|
+
The [examples](examples/) load their issue list and comments by infinite scroll.
|
|
325
|
+
|
|
276
326
|
### When the URL changes
|
|
277
327
|
|
|
278
328
|
Filters, sort order, and pagination are search params. The loader turns them into the query's input, so every navigation starts the right query and the component only ever reads the handle it was given:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raf-query/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "React bindings for raf-query, a render-as-you-fetch query library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"./tanstack-router": "./dist/tanstack-router.mjs"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@raf-query/core": "0.1.
|
|
43
|
+
"@raf-query/core": "0.1.8",
|
|
44
44
|
"effect": "^4.0.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|