@adaskothebeast/react-redux-toolkit-hierarchical-date-hook 1.0.0

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/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@adaskothebeast/react-redux-toolkit-hierarchical-date-hook",
3
+ "version": "1.0.0",
4
+ "peerDependencies": {
5
+ "@reduxjs/toolkit": "^1.9.5"
6
+ },
7
+ "devDependencies": {
8
+ "@adaskothebeast/hierarchical-convert-to-date": "1.0.0"
9
+ },
10
+ "module": "./index.js",
11
+ "main": "./index.js",
12
+ "type": "module",
13
+ "types": "./src\\index.d.ts"
14
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/react-redux-toolkit-hierarchical-date-hook';
@@ -0,0 +1,35 @@
1
+ import { UseQueryHookResult } from '@reduxjs/toolkit/dist/query/react/buildHooks';
2
+ import { BaseQueryFn, QueryDefinition, TypedUseQueryStateResult } from '@reduxjs/toolkit/query/react';
3
+ /**
4
+ * This custom hook transforms the string date fields based on matching regex to Date objects
5
+ * of a Redux Toolkit query result using the HierarchicalConverter.
6
+ * In cases of some libraries it is also possible to convert Period automatically.
7
+ * It deep-clones the data field and then performs the conversion.
8
+ * If there's no data, it returns the original query result unchanged.
9
+ *
10
+ * Usage:
11
+ * ```jsx
12
+ * // choose one function from below depending on library which you use for date manipulation
13
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
14
+ * import { hierarchicalConvertToDateFns } from '@adaskothebeast/hierarchical-convert-to-date-fns';
15
+ * import { hierarchicalConvertToDayjs } from '@adaskothebeast/hierarchical-convert-to-dayjs';
16
+ * import { hierarchicalConvertToJsJoda } from '@adaskothebeast/hierarchical-convert-to-js-joda';
17
+ * import { hierarchicalConvertToLuxon } from '@adaskothebeast/hierarchical-convert-to-luxon';
18
+ * import { hierarchicalConvertToMoment } from '@adaskothebeast/hierarchical-convert-to-moment';
19
+ *
20
+ * const MyComponent: React.FC = () => {
21
+ * // Call your generated hook here
22
+ * const useQueryResult = useQueryFunction(arg, options);
23
+ *
24
+ * // Pass the result to the custom hook
25
+ * const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, hierarchicalConvertToDate);
26
+ *
27
+ * // Rest of your component...
28
+ * }
29
+ * ```
30
+ *
31
+ * @param useQueryResult The result of a Redux Toolkit query hook
32
+ * @param convertFunc The function that performs the conversion in place
33
+ * @returns The original query result with its data field transformed, if it exists
34
+ */
35
+ export declare function useAdjustUseQueryHookResultWithHierarchicalDateConverter<ResultType, QueryArg, BaseQuery extends BaseQueryFn = BaseQueryFn, ReducerPath extends string = string, R extends TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery> = TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery>>(useQueryResult: UseQueryHookResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, ReducerPath>, R>, convertFunc: (obj: object) => void): UseQueryHookResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, ReducerPath>, R>;