@ainias42/tanstack-ids 0.1.1 → 0.1.2

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.
@@ -0,0 +1,7 @@
1
+ export declare function useInitialData<Type>(data: Type | undefined): {
2
+ initialData: NonNullable<Type>;
3
+ initialDataUpdatedAt: number;
4
+ } | {
5
+ initialData?: undefined;
6
+ initialDataUpdatedAt?: undefined;
7
+ };
@@ -0,0 +1,13 @@
1
+ import { DateHelper } from '@ainias42/js-helper';
2
+ import { useState } from 'react';
3
+ export function useInitialData(data) {
4
+ const [now] = useState(() => DateHelper.now());
5
+ if (data) {
6
+ return {
7
+ initialData: data,
8
+ initialDataUpdatedAt: now,
9
+ };
10
+ }
11
+ return {};
12
+ }
13
+ //# sourceMappingURL=useInitialData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInitialData.js","sourceRoot":"","sources":["../../src/hooks/useInitialData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,MAAM,UAAU,cAAc,CAAO,IAAsB;IACvD,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/C,IAAI,IAAI,EAAE,CAAC;QACP,OAAO;YACH,WAAW,EAAE,IAAI;YACjB,oBAAoB,EAAE,GAAG;SAC5B,CAAC;IACN,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './NotFoundError.js';
7
7
  export * from './hooks/formatInitialPage.js';
8
8
  export * from './hooks/useArrayData.js';
9
9
  export * from './hooks/useIndexedData.js';
10
+ export * from './hooks/useInitialData.js';
10
11
  export * from './QueryContext/QueriesContext.js';
11
12
  export * from './QueryContext/QueriesContextProvider.js';
12
13
  export * from './QueryContext/SubQueriesContext.js';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './NotFoundError.js';
7
7
  export * from './hooks/formatInitialPage.js';
8
8
  export * from './hooks/useArrayData.js';
9
9
  export * from './hooks/useIndexedData.js';
10
+ export * from './hooks/useInitialData.js';
10
11
  export * from './QueryContext/QueriesContext.js';
11
12
  export * from './QueryContext/QueriesContextProvider.js';
12
13
  export * from './QueryContext/SubQueriesContext.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainias42/tanstack-ids",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -0,0 +1,13 @@
1
+ import { DateHelper } from '@ainias42/js-helper';
2
+ import { useState } from 'react';
3
+
4
+ export function useInitialData<Type>(data: Type | undefined) {
5
+ const [now] = useState(() => DateHelper.now());
6
+ if (data) {
7
+ return {
8
+ initialData: data,
9
+ initialDataUpdatedAt: now,
10
+ };
11
+ }
12
+ return {};
13
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './NotFoundError';
7
7
  export * from './hooks/formatInitialPage';
8
8
  export * from './hooks/useArrayData';
9
9
  export * from './hooks/useIndexedData';
10
+ export * from './hooks/useInitialData';
10
11
  export * from './QueryContext/QueriesContext';
11
12
  export * from './QueryContext/QueriesContextProvider';
12
13
  export * from './QueryContext/SubQueriesContext';