@ventlio/tanstack-query 0.1.1 → 0.1.3
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/README.md +3 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -10
- package/dist/index.mjs.map +1 -1
- package/dist/queries/index.d.ts +4 -0
- package/dist/queries/queries.interface.d.ts +8 -0
- package/dist/queries/useDeleteRequest.d.ts +115 -0
- package/dist/queries/useGetRequest.d.ts +139 -0
- package/dist/queries/usePatchRequest.d.ts +78 -0
- package/dist/queries/usePostRequest.d.ts +78 -0
- package/package.json +2 -6
- package/src/helpers/index.ts +6 -0
- package/src/index.ts +0 -1
- package/src/queries/index.ts +4 -0
- package/src/queries/queries.interface.ts +8 -0
- package/src/queries/useDeleteRequest.ts +52 -0
- package/src/queries/useGetRequest.ts +140 -0
- package/src/queries/usePatchRequest.ts +61 -0
- package/src/queries/usePostRequest.ts +59 -0
- package/dist/useMyHook.d.ts +0 -1
- package/dist/useMyHook.js +0 -14
- package/dist/useMyHook.js.map +0 -1
- package/src/useMyHook.ts +0 -11
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const scrollToTop: () => void;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ var buildFormData = require('./request/buildFormData.js');
|
|
|
6
6
|
var makeRequest = require('./request/make-request.js');
|
|
7
7
|
var request_enum = require('./request/request.enum.js');
|
|
8
8
|
var transformer = require('./request/transformer.js');
|
|
9
|
-
var useMyHook = require('./useMyHook.js');
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
|
|
@@ -24,5 +23,4 @@ Object.defineProperty(exports, 'HttpMethod', {
|
|
|
24
23
|
});
|
|
25
24
|
exports.errorTransformer = transformer.errorTransformer;
|
|
26
25
|
exports.successTransformer = transformer.successTransformer;
|
|
27
|
-
exports.useMyHook = useMyHook.useMyHook;
|
|
28
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { useState } from 'react';
|
|
3
2
|
|
|
4
3
|
const API_BASE_URL = '';
|
|
5
4
|
|
|
@@ -98,13 +97,5 @@ async function makeRequest({ body, method = HttpMethod.GET, path, bearerToken, f
|
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
const [value, setValue] = useState('');
|
|
103
|
-
const updateValue = (newValue) => {
|
|
104
|
-
setValue(newValue);
|
|
105
|
-
};
|
|
106
|
-
return [value, updateValue];
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export { API_BASE_URL, ContentType, HttpMethod, axiosInstance, buildFormData, errorTransformer, makeRequest, successTransformer, useMyHook };
|
|
100
|
+
export { API_BASE_URL, ContentType, HttpMethod, axiosInstance, buildFormData, errorTransformer, makeRequest, successTransformer };
|
|
110
101
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { MutateOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
2
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
3
|
+
export declare const useDeleteRequest: <TResponse>() => {
|
|
4
|
+
data: IRequestSuccess<TResponse>;
|
|
5
|
+
error: any;
|
|
6
|
+
isError: true;
|
|
7
|
+
isLoading: false;
|
|
8
|
+
isLoadingError: false;
|
|
9
|
+
isRefetchError: true;
|
|
10
|
+
isSuccess: false;
|
|
11
|
+
status: "error";
|
|
12
|
+
dataUpdatedAt: number;
|
|
13
|
+
errorUpdatedAt: number;
|
|
14
|
+
failureCount: number;
|
|
15
|
+
failureReason: any;
|
|
16
|
+
errorUpdateCount: number;
|
|
17
|
+
isFetched: boolean;
|
|
18
|
+
isFetchedAfterMount: boolean;
|
|
19
|
+
isFetching: boolean;
|
|
20
|
+
isInitialLoading: boolean;
|
|
21
|
+
isPaused: boolean;
|
|
22
|
+
isPlaceholderData: boolean;
|
|
23
|
+
isPreviousData: boolean;
|
|
24
|
+
isRefetching: boolean;
|
|
25
|
+
isStale: boolean;
|
|
26
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
27
|
+
remove: () => void;
|
|
28
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
29
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
30
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
31
|
+
} | {
|
|
32
|
+
data: IRequestSuccess<TResponse>;
|
|
33
|
+
error: null;
|
|
34
|
+
isError: false;
|
|
35
|
+
isLoading: false;
|
|
36
|
+
isLoadingError: false;
|
|
37
|
+
isRefetchError: false;
|
|
38
|
+
isSuccess: true;
|
|
39
|
+
status: "success";
|
|
40
|
+
dataUpdatedAt: number;
|
|
41
|
+
errorUpdatedAt: number;
|
|
42
|
+
failureCount: number;
|
|
43
|
+
failureReason: any;
|
|
44
|
+
errorUpdateCount: number;
|
|
45
|
+
isFetched: boolean;
|
|
46
|
+
isFetchedAfterMount: boolean;
|
|
47
|
+
isFetching: boolean;
|
|
48
|
+
isInitialLoading: boolean;
|
|
49
|
+
isPaused: boolean;
|
|
50
|
+
isPlaceholderData: boolean;
|
|
51
|
+
isPreviousData: boolean;
|
|
52
|
+
isRefetching: boolean;
|
|
53
|
+
isStale: boolean;
|
|
54
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
55
|
+
remove: () => void;
|
|
56
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
57
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
58
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
59
|
+
} | {
|
|
60
|
+
data: undefined;
|
|
61
|
+
error: any;
|
|
62
|
+
isError: true;
|
|
63
|
+
isLoading: false;
|
|
64
|
+
isLoadingError: true;
|
|
65
|
+
isRefetchError: false;
|
|
66
|
+
isSuccess: false;
|
|
67
|
+
status: "error";
|
|
68
|
+
dataUpdatedAt: number;
|
|
69
|
+
errorUpdatedAt: number;
|
|
70
|
+
failureCount: number;
|
|
71
|
+
failureReason: any;
|
|
72
|
+
errorUpdateCount: number;
|
|
73
|
+
isFetched: boolean;
|
|
74
|
+
isFetchedAfterMount: boolean;
|
|
75
|
+
isFetching: boolean;
|
|
76
|
+
isInitialLoading: boolean;
|
|
77
|
+
isPaused: boolean;
|
|
78
|
+
isPlaceholderData: boolean;
|
|
79
|
+
isPreviousData: boolean;
|
|
80
|
+
isRefetching: boolean;
|
|
81
|
+
isStale: boolean;
|
|
82
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
83
|
+
remove: () => void;
|
|
84
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
85
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
86
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
87
|
+
} | {
|
|
88
|
+
data: undefined;
|
|
89
|
+
error: null;
|
|
90
|
+
isError: false;
|
|
91
|
+
isLoading: true;
|
|
92
|
+
isLoadingError: false;
|
|
93
|
+
isRefetchError: false;
|
|
94
|
+
isSuccess: false;
|
|
95
|
+
status: "loading";
|
|
96
|
+
dataUpdatedAt: number;
|
|
97
|
+
errorUpdatedAt: number;
|
|
98
|
+
failureCount: number;
|
|
99
|
+
failureReason: any;
|
|
100
|
+
errorUpdateCount: number;
|
|
101
|
+
isFetched: boolean;
|
|
102
|
+
isFetchedAfterMount: boolean;
|
|
103
|
+
isFetching: boolean;
|
|
104
|
+
isInitialLoading: boolean;
|
|
105
|
+
isPaused: boolean;
|
|
106
|
+
isPlaceholderData: boolean;
|
|
107
|
+
isPreviousData: boolean;
|
|
108
|
+
isRefetching: boolean;
|
|
109
|
+
isStale: boolean;
|
|
110
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
111
|
+
remove: () => void;
|
|
112
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
113
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
114
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
115
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
3
|
+
export declare const useGetRequest: <TResponse extends Record<string, any>>({ path, load, queryOptions, }: {
|
|
4
|
+
path: string;
|
|
5
|
+
load?: boolean | undefined;
|
|
6
|
+
queryOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined;
|
|
7
|
+
}) => {
|
|
8
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
9
|
+
nextPage: () => void;
|
|
10
|
+
prevPage: () => void;
|
|
11
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
12
|
+
gotoPage: (pageNumber: number) => void;
|
|
13
|
+
page: number;
|
|
14
|
+
queryKey: {}[];
|
|
15
|
+
data: IRequestSuccess<TResponse>;
|
|
16
|
+
error: any;
|
|
17
|
+
isError: true;
|
|
18
|
+
isLoading: false;
|
|
19
|
+
isLoadingError: false;
|
|
20
|
+
isRefetchError: true;
|
|
21
|
+
isSuccess: false;
|
|
22
|
+
status: "error";
|
|
23
|
+
dataUpdatedAt: number;
|
|
24
|
+
errorUpdatedAt: number;
|
|
25
|
+
failureCount: number;
|
|
26
|
+
failureReason: any;
|
|
27
|
+
errorUpdateCount: number;
|
|
28
|
+
isFetched: boolean;
|
|
29
|
+
isFetchedAfterMount: boolean;
|
|
30
|
+
isFetching: boolean;
|
|
31
|
+
isInitialLoading: boolean;
|
|
32
|
+
isPaused: boolean;
|
|
33
|
+
isPlaceholderData: boolean;
|
|
34
|
+
isPreviousData: boolean;
|
|
35
|
+
isRefetching: boolean;
|
|
36
|
+
isStale: boolean;
|
|
37
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
38
|
+
remove: () => void;
|
|
39
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
40
|
+
} | {
|
|
41
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
42
|
+
nextPage: () => void;
|
|
43
|
+
prevPage: () => void;
|
|
44
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
45
|
+
gotoPage: (pageNumber: number) => void;
|
|
46
|
+
page: number;
|
|
47
|
+
queryKey: {}[];
|
|
48
|
+
data: IRequestSuccess<TResponse>;
|
|
49
|
+
error: null;
|
|
50
|
+
isError: false;
|
|
51
|
+
isLoading: false;
|
|
52
|
+
isLoadingError: false;
|
|
53
|
+
isRefetchError: false;
|
|
54
|
+
isSuccess: true;
|
|
55
|
+
status: "success";
|
|
56
|
+
dataUpdatedAt: number;
|
|
57
|
+
errorUpdatedAt: number;
|
|
58
|
+
failureCount: number;
|
|
59
|
+
failureReason: any;
|
|
60
|
+
errorUpdateCount: number;
|
|
61
|
+
isFetched: boolean;
|
|
62
|
+
isFetchedAfterMount: boolean;
|
|
63
|
+
isFetching: boolean;
|
|
64
|
+
isInitialLoading: boolean;
|
|
65
|
+
isPaused: boolean;
|
|
66
|
+
isPlaceholderData: boolean;
|
|
67
|
+
isPreviousData: boolean;
|
|
68
|
+
isRefetching: boolean;
|
|
69
|
+
isStale: boolean;
|
|
70
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
71
|
+
remove: () => void;
|
|
72
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
73
|
+
} | {
|
|
74
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
75
|
+
nextPage: () => void;
|
|
76
|
+
prevPage: () => void;
|
|
77
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
78
|
+
gotoPage: (pageNumber: number) => void;
|
|
79
|
+
page: number;
|
|
80
|
+
queryKey: {}[];
|
|
81
|
+
data: undefined;
|
|
82
|
+
error: any;
|
|
83
|
+
isError: true;
|
|
84
|
+
isLoading: false;
|
|
85
|
+
isLoadingError: true;
|
|
86
|
+
isRefetchError: false;
|
|
87
|
+
isSuccess: false;
|
|
88
|
+
status: "error";
|
|
89
|
+
dataUpdatedAt: number;
|
|
90
|
+
errorUpdatedAt: number;
|
|
91
|
+
failureCount: number;
|
|
92
|
+
failureReason: any;
|
|
93
|
+
errorUpdateCount: number;
|
|
94
|
+
isFetched: boolean;
|
|
95
|
+
isFetchedAfterMount: boolean;
|
|
96
|
+
isFetching: boolean;
|
|
97
|
+
isInitialLoading: boolean;
|
|
98
|
+
isPaused: boolean;
|
|
99
|
+
isPlaceholderData: boolean;
|
|
100
|
+
isPreviousData: boolean;
|
|
101
|
+
isRefetching: boolean;
|
|
102
|
+
isStale: boolean;
|
|
103
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
104
|
+
remove: () => void;
|
|
105
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
106
|
+
} | {
|
|
107
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
108
|
+
nextPage: () => void;
|
|
109
|
+
prevPage: () => void;
|
|
110
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
111
|
+
gotoPage: (pageNumber: number) => void;
|
|
112
|
+
page: number;
|
|
113
|
+
queryKey: {}[];
|
|
114
|
+
data: undefined;
|
|
115
|
+
error: null;
|
|
116
|
+
isError: false;
|
|
117
|
+
isLoading: true;
|
|
118
|
+
isLoadingError: false;
|
|
119
|
+
isRefetchError: false;
|
|
120
|
+
isSuccess: false;
|
|
121
|
+
status: "loading";
|
|
122
|
+
dataUpdatedAt: number;
|
|
123
|
+
errorUpdatedAt: number;
|
|
124
|
+
failureCount: number;
|
|
125
|
+
failureReason: any;
|
|
126
|
+
errorUpdateCount: number;
|
|
127
|
+
isFetched: boolean;
|
|
128
|
+
isFetchedAfterMount: boolean;
|
|
129
|
+
isFetching: boolean;
|
|
130
|
+
isInitialLoading: boolean;
|
|
131
|
+
isPaused: boolean;
|
|
132
|
+
isPlaceholderData: boolean;
|
|
133
|
+
isPreviousData: boolean;
|
|
134
|
+
isRefetching: boolean;
|
|
135
|
+
isStale: boolean;
|
|
136
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
137
|
+
remove: () => void;
|
|
138
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
139
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { MutateOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { IRequestError, IRequestSuccess } from '../request/request.interface';
|
|
3
|
+
export declare const usePatchRequest: <TResponse>({ path, formData, }: {
|
|
4
|
+
path: string;
|
|
5
|
+
formData?: boolean | undefined;
|
|
6
|
+
}) => {
|
|
7
|
+
resetForm: boolean;
|
|
8
|
+
data: undefined;
|
|
9
|
+
error: null;
|
|
10
|
+
isError: false;
|
|
11
|
+
isIdle: true;
|
|
12
|
+
isLoading: false;
|
|
13
|
+
isSuccess: false;
|
|
14
|
+
status: "idle";
|
|
15
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
16
|
+
reset: () => void;
|
|
17
|
+
context: unknown;
|
|
18
|
+
failureCount: number;
|
|
19
|
+
failureReason: IRequestError | null;
|
|
20
|
+
isPaused: boolean;
|
|
21
|
+
variables: void | undefined;
|
|
22
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
23
|
+
patch: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
24
|
+
} | {
|
|
25
|
+
resetForm: boolean;
|
|
26
|
+
data: undefined;
|
|
27
|
+
error: null;
|
|
28
|
+
isError: false;
|
|
29
|
+
isIdle: false;
|
|
30
|
+
isLoading: true;
|
|
31
|
+
isSuccess: false;
|
|
32
|
+
status: "loading";
|
|
33
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
context: unknown;
|
|
36
|
+
failureCount: number;
|
|
37
|
+
failureReason: IRequestError | null;
|
|
38
|
+
isPaused: boolean;
|
|
39
|
+
variables: void | undefined;
|
|
40
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
41
|
+
patch: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
42
|
+
} | {
|
|
43
|
+
resetForm: boolean;
|
|
44
|
+
data: undefined;
|
|
45
|
+
error: IRequestError;
|
|
46
|
+
isError: true;
|
|
47
|
+
isIdle: false;
|
|
48
|
+
isLoading: false;
|
|
49
|
+
isSuccess: false;
|
|
50
|
+
status: "error";
|
|
51
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
52
|
+
reset: () => void;
|
|
53
|
+
context: unknown;
|
|
54
|
+
failureCount: number;
|
|
55
|
+
failureReason: IRequestError | null;
|
|
56
|
+
isPaused: boolean;
|
|
57
|
+
variables: void | undefined;
|
|
58
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
59
|
+
patch: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
60
|
+
} | {
|
|
61
|
+
resetForm: boolean;
|
|
62
|
+
data: IRequestSuccess<TResponse>;
|
|
63
|
+
error: null;
|
|
64
|
+
isError: false;
|
|
65
|
+
isIdle: false;
|
|
66
|
+
isLoading: false;
|
|
67
|
+
isSuccess: true;
|
|
68
|
+
status: "success";
|
|
69
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
70
|
+
reset: () => void;
|
|
71
|
+
context: unknown;
|
|
72
|
+
failureCount: number;
|
|
73
|
+
failureReason: IRequestError | null;
|
|
74
|
+
isPaused: boolean;
|
|
75
|
+
variables: void | undefined;
|
|
76
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
77
|
+
patch: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
78
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { MutateOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
3
|
+
export declare const usePostRequest: <TResponse>({ path, formData, }: {
|
|
4
|
+
path: string;
|
|
5
|
+
formData?: boolean | undefined;
|
|
6
|
+
}) => {
|
|
7
|
+
resetForm: boolean;
|
|
8
|
+
data: undefined;
|
|
9
|
+
error: null;
|
|
10
|
+
isError: false;
|
|
11
|
+
isIdle: true;
|
|
12
|
+
isLoading: false;
|
|
13
|
+
isSuccess: false;
|
|
14
|
+
status: "idle";
|
|
15
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
16
|
+
reset: () => void;
|
|
17
|
+
context: unknown;
|
|
18
|
+
failureCount: number;
|
|
19
|
+
failureReason: IRequestError | null;
|
|
20
|
+
isPaused: boolean;
|
|
21
|
+
variables: void | undefined;
|
|
22
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
23
|
+
post: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
24
|
+
} | {
|
|
25
|
+
resetForm: boolean;
|
|
26
|
+
data: undefined;
|
|
27
|
+
error: null;
|
|
28
|
+
isError: false;
|
|
29
|
+
isIdle: false;
|
|
30
|
+
isLoading: true;
|
|
31
|
+
isSuccess: false;
|
|
32
|
+
status: "loading";
|
|
33
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
context: unknown;
|
|
36
|
+
failureCount: number;
|
|
37
|
+
failureReason: IRequestError | null;
|
|
38
|
+
isPaused: boolean;
|
|
39
|
+
variables: void | undefined;
|
|
40
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
41
|
+
post: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
42
|
+
} | {
|
|
43
|
+
resetForm: boolean;
|
|
44
|
+
data: undefined;
|
|
45
|
+
error: IRequestError;
|
|
46
|
+
isError: true;
|
|
47
|
+
isIdle: false;
|
|
48
|
+
isLoading: false;
|
|
49
|
+
isSuccess: false;
|
|
50
|
+
status: "error";
|
|
51
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
52
|
+
reset: () => void;
|
|
53
|
+
context: unknown;
|
|
54
|
+
failureCount: number;
|
|
55
|
+
failureReason: IRequestError | null;
|
|
56
|
+
isPaused: boolean;
|
|
57
|
+
variables: void | undefined;
|
|
58
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
59
|
+
post: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
60
|
+
} | {
|
|
61
|
+
resetForm: boolean;
|
|
62
|
+
data: IRequestSuccess<TResponse>;
|
|
63
|
+
error: null;
|
|
64
|
+
isError: false;
|
|
65
|
+
isIdle: false;
|
|
66
|
+
isLoading: false;
|
|
67
|
+
isSuccess: true;
|
|
68
|
+
status: "success";
|
|
69
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
70
|
+
reset: () => void;
|
|
71
|
+
context: unknown;
|
|
72
|
+
failureCount: number;
|
|
73
|
+
failureReason: IRequestError | null;
|
|
74
|
+
isPaused: boolean;
|
|
75
|
+
variables: void | undefined;
|
|
76
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, void, unknown>;
|
|
77
|
+
post: (postData: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse>>;
|
|
78
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ventlio/tanstack-query",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -62,11 +62,7 @@
|
|
|
62
62
|
"typescript": "^4.9.5"
|
|
63
63
|
},
|
|
64
64
|
"files": [
|
|
65
|
-
"dist/app/*",
|
|
66
65
|
"dist/**/*",
|
|
67
66
|
"src"
|
|
68
|
-
]
|
|
69
|
-
"dependencies": {
|
|
70
|
-
"rmf": "^2.0.0"
|
|
71
|
-
}
|
|
67
|
+
]
|
|
72
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { MutateOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
5
|
+
import { HttpMethod, makeRequest } from '../request';
|
|
6
|
+
|
|
7
|
+
export const useDeleteRequest = <TResponse>() => {
|
|
8
|
+
const [requestPath, updateDeletePath] = useState<string>('');
|
|
9
|
+
const [options, setOptions] = useState<any>();
|
|
10
|
+
const authToken = '';
|
|
11
|
+
const query = useQuery<any, any, IRequestSuccess<TResponse>>(
|
|
12
|
+
[requestPath, {}],
|
|
13
|
+
() =>
|
|
14
|
+
new Promise<IRequestSuccess<TResponse> | IRequestError>((res, rej) => {
|
|
15
|
+
setTimeout(async () => {
|
|
16
|
+
const postResponse = await makeRequest<TResponse>({
|
|
17
|
+
path: requestPath,
|
|
18
|
+
bearerToken: authToken,
|
|
19
|
+
method: HttpMethod.DELETE,
|
|
20
|
+
});
|
|
21
|
+
if (postResponse.status) {
|
|
22
|
+
res(postResponse as IRequestSuccess<TResponse>);
|
|
23
|
+
} else {
|
|
24
|
+
rej(postResponse);
|
|
25
|
+
}
|
|
26
|
+
}, 200);
|
|
27
|
+
}),
|
|
28
|
+
{ ...options }
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const updatedPathAsync = async (link: string) => {
|
|
32
|
+
return updateDeletePath(link);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const setOptionsAsync = async (fetchOptions: any) => {
|
|
36
|
+
return setOptions(fetchOptions);
|
|
37
|
+
};
|
|
38
|
+
const deleteR = async (
|
|
39
|
+
link: string,
|
|
40
|
+
fetchOptions?:
|
|
41
|
+
| MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown>
|
|
42
|
+
| undefined
|
|
43
|
+
): Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>> => {
|
|
44
|
+
await updatedPathAsync(link);
|
|
45
|
+
await setOptionsAsync(fetchOptions);
|
|
46
|
+
|
|
47
|
+
return query.refetch<TResponse>({
|
|
48
|
+
queryKey: [link, {}],
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return { updateDeletePath, deleteR, ...query };
|
|
52
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { startTransition, useState } from 'react';
|
|
4
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
5
|
+
import { makeRequest } from '../request';
|
|
6
|
+
import type { IPagination } from './queries.interface';
|
|
7
|
+
|
|
8
|
+
export const useGetRequest = <TResponse extends Record<string, any>>({
|
|
9
|
+
path,
|
|
10
|
+
load = false,
|
|
11
|
+
queryOptions,
|
|
12
|
+
}: {
|
|
13
|
+
path: string;
|
|
14
|
+
load?: boolean;
|
|
15
|
+
queryOptions?: UseQueryOptions<
|
|
16
|
+
IRequestSuccess<TResponse | undefined>,
|
|
17
|
+
IRequestError,
|
|
18
|
+
IRequestSuccess<TResponse | undefined>,
|
|
19
|
+
Array<any>
|
|
20
|
+
>;
|
|
21
|
+
}) => {
|
|
22
|
+
const [requestPath, updatePath] = useState<string>(path);
|
|
23
|
+
const authToken = '';
|
|
24
|
+
const [options, setOptions] = useState<any>(queryOptions);
|
|
25
|
+
const [page, setPage] = useState<number>(1);
|
|
26
|
+
|
|
27
|
+
const query = useQuery<any, any, IRequestSuccess<TResponse>>(
|
|
28
|
+
[requestPath, {}],
|
|
29
|
+
() =>
|
|
30
|
+
new Promise<IRequestSuccess<TResponse> | IRequestError>((res, rej) => {
|
|
31
|
+
// work on removing this setTimeout, it was added to delay for the requestPath to be updated successfully
|
|
32
|
+
// could have used hook for this but will miss the purpose
|
|
33
|
+
setTimeout(async () => {
|
|
34
|
+
const postResponse = await makeRequest<TResponse>({
|
|
35
|
+
path: requestPath,
|
|
36
|
+
bearerToken: authToken,
|
|
37
|
+
});
|
|
38
|
+
if (postResponse.status) {
|
|
39
|
+
res(postResponse as IRequestSuccess<TResponse>);
|
|
40
|
+
} else {
|
|
41
|
+
rej(postResponse);
|
|
42
|
+
}
|
|
43
|
+
}, 200);
|
|
44
|
+
}),
|
|
45
|
+
{
|
|
46
|
+
enabled: load,
|
|
47
|
+
...options,
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const nextPage = () => {
|
|
52
|
+
if (query.data?.data.pagination) {
|
|
53
|
+
const pagination: IPagination = query.data.data.pagination;
|
|
54
|
+
if (
|
|
55
|
+
pagination.next_page !== pagination.current_page &&
|
|
56
|
+
pagination.next_page > pagination.current_page
|
|
57
|
+
) {
|
|
58
|
+
updatePath(constructPaginationLink(requestPath, pagination.next_page));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const constructPaginationLink = (link: string, pageNumber: number) => {
|
|
64
|
+
const oldLink = link;
|
|
65
|
+
if (link.includes('?')) {
|
|
66
|
+
if (link.includes('?page=')) {
|
|
67
|
+
// replace current page number with new number
|
|
68
|
+
link = link.replace(/\?page=(\d+)/gim, `?page=${pageNumber}`);
|
|
69
|
+
} else if (link.includes('&page=')) {
|
|
70
|
+
link = link.replace(/&page=(\d+)/gim, `&page=${pageNumber}`);
|
|
71
|
+
} else {
|
|
72
|
+
link = `${link}&page=${pageNumber}`;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
link = `${link}?page=${pageNumber}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// only update page when pagination is done
|
|
79
|
+
if (oldLink !== link) {
|
|
80
|
+
setPage(pageNumber);
|
|
81
|
+
}
|
|
82
|
+
return link;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const prevPage = () => {
|
|
86
|
+
if (query.data?.data.pagination) {
|
|
87
|
+
const pagination: IPagination = query.data.data.pagination;
|
|
88
|
+
if (
|
|
89
|
+
pagination.previous_page !== pagination.current_page &&
|
|
90
|
+
pagination.previous_page < pagination.current_page
|
|
91
|
+
) {
|
|
92
|
+
updatePath(
|
|
93
|
+
constructPaginationLink(requestPath, pagination.previous_page)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const gotoPage = (pageNumber: number) => {
|
|
100
|
+
updatePath(constructPaginationLink(requestPath, pageNumber));
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const updatedPathAsync = async (link: string) => {
|
|
104
|
+
startTransition(() => {
|
|
105
|
+
updatePath(link);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const setOptionsAsync = async (fetchOptions: any) => {
|
|
110
|
+
startTransition(() => {
|
|
111
|
+
setOptions(fetchOptions);
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const get = async (
|
|
116
|
+
link: string,
|
|
117
|
+
fetchOptions?: UseQueryOptions<
|
|
118
|
+
IRequestSuccess<TResponse | undefined>,
|
|
119
|
+
IRequestError,
|
|
120
|
+
IRequestSuccess<TResponse | undefined>,
|
|
121
|
+
Array<any>
|
|
122
|
+
>
|
|
123
|
+
): Promise<IRequestSuccess<TResponse> | undefined> => {
|
|
124
|
+
await setOptionsAsync(fetchOptions);
|
|
125
|
+
await updatedPathAsync(link);
|
|
126
|
+
|
|
127
|
+
return query.data;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
...query,
|
|
132
|
+
updatePath,
|
|
133
|
+
nextPage,
|
|
134
|
+
prevPage,
|
|
135
|
+
get,
|
|
136
|
+
gotoPage,
|
|
137
|
+
page,
|
|
138
|
+
queryKey: [requestPath, {}],
|
|
139
|
+
};
|
|
140
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { MutateOptions } from '@tanstack/react-query';
|
|
2
|
+
import { useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { scrollToTop } from '../helpers';
|
|
5
|
+
import { HttpMethod, makeRequest } from '../request';
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
IRequestError,
|
|
9
|
+
IRequestSuccess,
|
|
10
|
+
} from '../request/request.interface';
|
|
11
|
+
|
|
12
|
+
export const usePatchRequest = <TResponse>({
|
|
13
|
+
path,
|
|
14
|
+
formData = false,
|
|
15
|
+
}: {
|
|
16
|
+
path: string;
|
|
17
|
+
formData?: boolean;
|
|
18
|
+
}) => {
|
|
19
|
+
const authToken = '';
|
|
20
|
+
const [resetForm, setResetForm] = useState<boolean>(false);
|
|
21
|
+
|
|
22
|
+
// register post mutation
|
|
23
|
+
const mutation = useMutation<IRequestSuccess<TResponse>, IRequestError>(
|
|
24
|
+
(postData: any) =>
|
|
25
|
+
new Promise<IRequestSuccess<TResponse>>((res, rej) => {
|
|
26
|
+
setResetForm(false);
|
|
27
|
+
|
|
28
|
+
makeRequest<TResponse>({
|
|
29
|
+
path: path,
|
|
30
|
+
body: postData,
|
|
31
|
+
method: HttpMethod.PATCH,
|
|
32
|
+
bearerToken: authToken,
|
|
33
|
+
formData,
|
|
34
|
+
}).then((postResponse) => {
|
|
35
|
+
if (postResponse.status) {
|
|
36
|
+
setResetForm(true);
|
|
37
|
+
// scroll to top after success
|
|
38
|
+
scrollToTop();
|
|
39
|
+
res(postResponse as IRequestSuccess<TResponse>);
|
|
40
|
+
} else {
|
|
41
|
+
// scroll to top after error
|
|
42
|
+
window.scrollTo({
|
|
43
|
+
top: 0,
|
|
44
|
+
behavior: 'smooth',
|
|
45
|
+
});
|
|
46
|
+
rej(postResponse);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
const patch = async (
|
|
52
|
+
postData: any,
|
|
53
|
+
options?:
|
|
54
|
+
| MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown>
|
|
55
|
+
| undefined
|
|
56
|
+
): Promise<IRequestSuccess<TResponse>> => {
|
|
57
|
+
return mutation.mutateAsync(postData, options);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return { patch, ...mutation, resetForm };
|
|
61
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { MutateOptions } from '@tanstack/react-query';
|
|
2
|
+
import { useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
5
|
+
import { HttpMethod, makeRequest } from '../request';
|
|
6
|
+
|
|
7
|
+
export const usePostRequest = <TResponse>({
|
|
8
|
+
path,
|
|
9
|
+
formData = false,
|
|
10
|
+
}: {
|
|
11
|
+
path: string;
|
|
12
|
+
formData?: boolean;
|
|
13
|
+
}) => {
|
|
14
|
+
const authToken = '';
|
|
15
|
+
|
|
16
|
+
const [resetForm, setResetForm] = useState<boolean>(false);
|
|
17
|
+
|
|
18
|
+
// register post mutation
|
|
19
|
+
const mutation = useMutation<IRequestSuccess<TResponse>, IRequestError>(
|
|
20
|
+
async (postData: any) =>
|
|
21
|
+
new Promise<IRequestSuccess<TResponse>>((res, rej) => {
|
|
22
|
+
setResetForm(false);
|
|
23
|
+
makeRequest<TResponse>({
|
|
24
|
+
path: path,
|
|
25
|
+
body: postData,
|
|
26
|
+
method: HttpMethod.POST,
|
|
27
|
+
bearerToken: authToken,
|
|
28
|
+
formData,
|
|
29
|
+
}).then((postResponse) => {
|
|
30
|
+
if (postResponse.status) {
|
|
31
|
+
setResetForm(true);
|
|
32
|
+
// scroll to top after success
|
|
33
|
+
window.scrollTo({
|
|
34
|
+
top: 0,
|
|
35
|
+
behavior: 'smooth',
|
|
36
|
+
});
|
|
37
|
+
res(postResponse as IRequestSuccess<TResponse>);
|
|
38
|
+
} else {
|
|
39
|
+
// scroll to top after error
|
|
40
|
+
window.scrollTo({
|
|
41
|
+
top: 0,
|
|
42
|
+
behavior: 'smooth',
|
|
43
|
+
});
|
|
44
|
+
rej(postResponse);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
const post = async (
|
|
50
|
+
postData: any,
|
|
51
|
+
options?:
|
|
52
|
+
| MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown>
|
|
53
|
+
| undefined
|
|
54
|
+
): Promise<IRequestSuccess<TResponse>> => {
|
|
55
|
+
return mutation.mutateAsync(postData, options);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return { post, ...mutation, resetForm };
|
|
59
|
+
};
|
package/dist/useMyHook.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useMyHook: () => [string, (newValue: string) => void];
|
package/dist/useMyHook.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
const useMyHook = () => {
|
|
6
|
-
const [value, setValue] = react.useState('');
|
|
7
|
-
const updateValue = (newValue) => {
|
|
8
|
-
setValue(newValue);
|
|
9
|
-
};
|
|
10
|
-
return [value, updateValue];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
exports.useMyHook = useMyHook;
|
|
14
|
-
//# sourceMappingURL=useMyHook.js.map
|
package/dist/useMyHook.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMyHook.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
package/src/useMyHook.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
|
|
3
|
-
export const useMyHook = (): [string, (newValue: string) => void] => {
|
|
4
|
-
const [value, setValue] = useState('');
|
|
5
|
-
|
|
6
|
-
const updateValue = (newValue: string) => {
|
|
7
|
-
setValue(newValue);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return [value, updateValue];
|
|
11
|
-
};
|