Skip to content

Commit beeb6b3

Browse files
committed
feat: export query keys
1 parent 0f4d602 commit beeb6b3

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/createUseQuery.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,30 @@ export const createUseQuery = (
3939
),
4040
);
4141
}
42-
return ts.factory.createVariableStatement(
42+
43+
const customHookName = `use${className}${capitalizeFirstLetter(methodName)}`;
44+
const queryKey = `${customHookName}Key`
45+
46+
return [
47+
ts.factory.createVariableStatement(
48+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
49+
ts.factory.createVariableDeclarationList(
50+
[ts.factory.createVariableDeclaration(
51+
ts.factory.createIdentifier(queryKey),
52+
undefined,
53+
undefined,
54+
ts.factory.createStringLiteral(`${className}${capitalizeFirstLetter(methodName)}`)
55+
)],
56+
ts.NodeFlags.Const
57+
)
58+
),
59+
ts.factory.createVariableStatement(
4360
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
4461
ts.factory.createVariableDeclarationList(
4562
[
4663
ts.factory.createVariableDeclaration(
4764
ts.factory.createIdentifier(
48-
`use${className}${capitalizeFirstLetter(methodName)}`
65+
customHookName
4966
),
5067
undefined,
5168
undefined,
@@ -146,9 +163,7 @@ export const createUseQuery = (
146163
[
147164
ts.factory.createArrayLiteralExpression(
148165
[
149-
ts.factory.createStringLiteral(
150-
`${className}${capitalizeFirstLetter(methodName)}`
151-
),
166+
ts.factory.createIdentifier(queryKey),
152167
ts.factory.createSpreadElement(ts.factory.createIdentifier("queryKey"))
153168
],
154169
false
@@ -178,5 +193,5 @@ export const createUseQuery = (
178193
],
179194
ts.NodeFlags.Const
180195
)
181-
);
196+
)];
182197
};

0 commit comments

Comments
 (0)