@trackunit/react-graphql-hooks 1.15.14 → 1.15.15

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.
Files changed (3) hide show
  1. package/index.cjs.js +17 -10
  2. package/index.esm.js +18 -11
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -474,19 +474,26 @@ const usePaginationQuery = (document, props) => {
474
474
  react.useEffect(() => {
475
475
  isInitializedRef.current = true;
476
476
  }, []);
477
- // Fetch the initial page on mount, whenever resetTrigger changes, or when
478
- // skip transitions (so an initially-skipped query fires once unskipped).
477
+ reactComponents.useWatch({
478
+ value: props.skip,
479
+ onChange: (skip, prevSkip) => {
480
+ if (prevSkip && !skip) {
481
+ dispatch({ type: "INCREMENT_RESET_TRIGGER" });
482
+ }
483
+ },
484
+ });
485
+ // Fetch the initial page on mount and whenever resetTrigger changes.
479
486
  // Variable changes flow through the reset effect above which increments
480
- // resetTrigger, so stableVariables is intentionally NOT a dependency here.
487
+ // resetTrigger. Skip true→false transitions increment it via the effect above.
488
+ const fetchVariables = react.useMemo(() => ({
489
+ first: latestRef.current.first ?? pageSize,
490
+ last: undefined,
491
+ before: undefined,
492
+ after: latestRef.current.after ?? undefined,
493
+ }), [pageSize]);
481
494
  react.useEffect(() => {
482
- const fetchVariables = {
483
- first: latestRef.current.first ?? pageSize,
484
- last: undefined,
485
- before: undefined,
486
- after: latestRef.current.after ?? undefined,
487
- };
488
495
  latestRef.current.executeFetch(fetchVariables, undefined, "initial");
489
- }, [state.resetTrigger, pageSize, props.skip]);
496
+ }, [state.resetTrigger, fetchVariables]);
490
497
  // Fetch next/previous page when relay cursor changes
491
498
  react.useEffect(() => {
492
499
  if (!hasLoadedDataRef.current) {
package/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { registerTranslations } from '@trackunit/i18n-library-translation';
3
3
  import { useLazyQuery as useLazyQuery$1, NetworkStatus, useQuery as useQuery$1 } from '@apollo/client';
4
4
  import { omit, isEqual } from 'es-toolkit';
5
5
  import { useMemo, useState, useReducer, useRef, useEffect, useCallback } from 'react';
6
- import { defaultPageSize, useRelayPagination } from '@trackunit/react-components';
6
+ import { defaultPageSize, useRelayPagination, useWatch } from '@trackunit/react-components';
7
7
  import { truthy, objectKeys } from '@trackunit/shared-utils';
8
8
 
9
9
  var defaultTranslations = {
@@ -472,19 +472,26 @@ const usePaginationQuery = (document, props) => {
472
472
  useEffect(() => {
473
473
  isInitializedRef.current = true;
474
474
  }, []);
475
- // Fetch the initial page on mount, whenever resetTrigger changes, or when
476
- // skip transitions (so an initially-skipped query fires once unskipped).
475
+ useWatch({
476
+ value: props.skip,
477
+ onChange: (skip, prevSkip) => {
478
+ if (prevSkip && !skip) {
479
+ dispatch({ type: "INCREMENT_RESET_TRIGGER" });
480
+ }
481
+ },
482
+ });
483
+ // Fetch the initial page on mount and whenever resetTrigger changes.
477
484
  // Variable changes flow through the reset effect above which increments
478
- // resetTrigger, so stableVariables is intentionally NOT a dependency here.
485
+ // resetTrigger. Skip true→false transitions increment it via the effect above.
486
+ const fetchVariables = useMemo(() => ({
487
+ first: latestRef.current.first ?? pageSize,
488
+ last: undefined,
489
+ before: undefined,
490
+ after: latestRef.current.after ?? undefined,
491
+ }), [pageSize]);
479
492
  useEffect(() => {
480
- const fetchVariables = {
481
- first: latestRef.current.first ?? pageSize,
482
- last: undefined,
483
- before: undefined,
484
- after: latestRef.current.after ?? undefined,
485
- };
486
493
  latestRef.current.executeFetch(fetchVariables, undefined, "initial");
487
- }, [state.resetTrigger, pageSize, props.skip]);
494
+ }, [state.resetTrigger, fetchVariables]);
488
495
  // Fetch next/previous page when relay cursor changes
489
496
  useEffect(() => {
490
497
  if (!hasLoadedDataRef.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-hooks",
3
- "version": "1.15.14",
3
+ "version": "1.15.15",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {