@vladimirdev635/gql-client-react 0.0.31 → 0.0.33
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 +3 -2
- package/useLazyOperation.jsx +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vladimirdev635/gql-client-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"@types/react": "^19.1.8",
|
|
33
33
|
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
|
34
34
|
"@vitejs/plugin-react": "^4.6.0",
|
|
35
|
-
"eslint": "^9.
|
|
35
|
+
"eslint": "^9.31.0",
|
|
36
|
+
"eslint-plugin-react": "^7.37.5",
|
|
36
37
|
"jiti": "^2.4.2",
|
|
37
38
|
"jsdom": "^26.1.0",
|
|
38
39
|
"vitest": "^3.2.4"
|
package/useLazyOperation.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadingState } from './useOperation.jsx';
|
|
2
|
-
import { useState } from 'react';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
3
|
export const lazyInitialState = Object.freeze({ state: 'initial' });
|
|
4
4
|
async function execute(executor, operation, variables, requestContext, setState) {
|
|
5
5
|
let newState;
|
|
@@ -15,11 +15,12 @@ async function execute(executor, operation, variables, requestContext, setState)
|
|
|
15
15
|
}
|
|
16
16
|
export function useLazyOperation(executor, operation) {
|
|
17
17
|
const [state, setState] = useState(lazyInitialState);
|
|
18
|
+
const executeCallback = useCallback((variables, requestContext) => {
|
|
19
|
+
setState(loadingState);
|
|
20
|
+
return execute(executor, operation, variables, requestContext, setState);
|
|
21
|
+
}, [setState, executor, operation]);
|
|
18
22
|
return {
|
|
19
|
-
execute:
|
|
20
|
-
setState(loadingState);
|
|
21
|
-
return execute(executor, operation, variables, requestContext, setState);
|
|
22
|
-
},
|
|
23
|
+
execute: executeCallback,
|
|
23
24
|
state,
|
|
24
25
|
reset: () => setState(lazyInitialState)
|
|
25
26
|
};
|