@spoosh/react 0.1.2 → 0.1.4

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/dist/index.js CHANGED
@@ -440,11 +440,15 @@ function createUseInfiniteRead(options) {
440
440
  controller.getState,
441
441
  controller.getState
442
442
  );
443
+ const [isPending, setIsPending] = (0, import_react3.useState)(() => {
444
+ return enabled && state.data === void 0;
445
+ });
443
446
  const fetchingDirection = controller.getFetchingDirection();
444
447
  const fetching = fetchingDirection !== null;
445
448
  const fetchingNext = fetchingDirection === "next";
446
449
  const fetchingPrev = fetchingDirection === "prev";
447
- const loading = fetching && state.data === void 0;
450
+ const hasData = state.data !== void 0;
451
+ const loading = (isPending || fetching) && !hasData;
448
452
  const lifecycleRef = (0, import_react3.useRef)({
449
453
  initialized: false,
450
454
  prevContext: null
@@ -465,7 +469,8 @@ function createUseInfiniteRead(options) {
465
469
  (tag) => resolvedTags.includes(tag)
466
470
  );
467
471
  if (hasMatch) {
468
- controller.refetch();
472
+ setIsPending(true);
473
+ controller.refetch().finally(() => setIsPending(false));
469
474
  }
470
475
  }
471
476
  );
@@ -479,7 +484,8 @@ function createUseInfiniteRead(options) {
479
484
  const currentState = controller.getState();
480
485
  const isFetching = controller.getFetchingDirection() !== null;
481
486
  if (currentState.data === void 0 && !isFetching) {
482
- controller.fetchNext();
487
+ setIsPending(true);
488
+ controller.fetchNext().finally(() => setIsPending(false));
483
489
  }
484
490
  }
485
491
  }, [enabled]);
package/dist/index.mjs CHANGED
@@ -330,7 +330,13 @@ function createUseWrite(options) {
330
330
  }
331
331
 
332
332
  // src/useInfiniteRead/index.ts
333
- import { useRef as useRef3, useEffect as useEffect2, useSyncExternalStore as useSyncExternalStore3, useId as useId3 } from "react";
333
+ import {
334
+ useRef as useRef3,
335
+ useEffect as useEffect2,
336
+ useSyncExternalStore as useSyncExternalStore3,
337
+ useId as useId3,
338
+ useState as useState3
339
+ } from "react";
334
340
  import {
335
341
  createInfiniteReadController,
336
342
  createSelectorProxy as createSelectorProxy3,
@@ -440,11 +446,15 @@ function createUseInfiniteRead(options) {
440
446
  controller.getState,
441
447
  controller.getState
442
448
  );
449
+ const [isPending, setIsPending] = useState3(() => {
450
+ return enabled && state.data === void 0;
451
+ });
443
452
  const fetchingDirection = controller.getFetchingDirection();
444
453
  const fetching = fetchingDirection !== null;
445
454
  const fetchingNext = fetchingDirection === "next";
446
455
  const fetchingPrev = fetchingDirection === "prev";
447
- const loading = fetching && state.data === void 0;
456
+ const hasData = state.data !== void 0;
457
+ const loading = (isPending || fetching) && !hasData;
448
458
  const lifecycleRef = useRef3({
449
459
  initialized: false,
450
460
  prevContext: null
@@ -465,7 +475,8 @@ function createUseInfiniteRead(options) {
465
475
  (tag) => resolvedTags.includes(tag)
466
476
  );
467
477
  if (hasMatch) {
468
- controller.refetch();
478
+ setIsPending(true);
479
+ controller.refetch().finally(() => setIsPending(false));
469
480
  }
470
481
  }
471
482
  );
@@ -479,7 +490,8 @@ function createUseInfiniteRead(options) {
479
490
  const currentState = controller.getState();
480
491
  const isFetching = controller.getFetchingDirection() !== null;
481
492
  if (currentState.data === void 0 && !isFetching) {
482
- controller.fetchNext();
493
+ setIsPending(true);
494
+ controller.fetchNext().finally(() => setIsPending(false));
483
495
  }
484
496
  }
485
497
  }, [enabled]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/react",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "description": "React hooks for Spoosh API client",
6
6
  "keywords": [
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@spoosh/core": "0.2.1"
37
+ "@spoosh/core": "0.3.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^18 || ^19"