@vladimirdev635/gql-client-react 0.0.51 → 0.0.52

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vladimirdev635/gql-client-react",
3
- "version": "0.0.51",
3
+ "version": "0.0.52",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -6,9 +6,9 @@ import { testOperation } from './utils.js';
6
6
  describe('useLazyOperation', () => {
7
7
  it('Should preserve initial state if no one calls', async () => {
8
8
  const { result } = renderHook(() => useLazyOperation({}, testOperation));
9
- expect(result.current.state.state).toBe('initial');
9
+ expect(result.current[1].state.state).toBe('initial');
10
10
  await act(async () => { });
11
- expect(result.current.state.state).toBe('initial');
11
+ expect(result.current[1].state.state).toBe('initial');
12
12
  });
13
13
  it('Should return loading state after invoking, then success state', async () => {
14
14
  const executor = async () => ({
@@ -18,16 +18,16 @@ describe('useLazyOperation', () => {
18
18
  const { result } = renderHook(() => useLazyOperation(executor, testOperation));
19
19
  let promise;
20
20
  act(() => {
21
- promise = result.current.execute({}, {});
21
+ promise = result.current[0]({}, {});
22
22
  });
23
- expect(result.current.state.state).toBe('loading');
23
+ expect(result.current[1].state.state).toBe('loading');
24
24
  // @ts-expect-error 2454
25
25
  const newState = await promise;
26
26
  expect(newState.state).toBe('success');
27
27
  assert(newState.state === 'success');
28
28
  expect(newState.result).toStrictEqual({ a: 1 });
29
29
  await act(async () => { });
30
- expect(result.current.state).toStrictEqual(newState);
30
+ expect(result.current[1].state).toStrictEqual(newState);
31
31
  });
32
32
  it('Should return loading state after invoking, then failure state', async () => {
33
33
  const error = new Error('Network error');
@@ -35,15 +35,15 @@ describe('useLazyOperation', () => {
35
35
  const { result } = renderHook(() => useLazyOperation(executor, testOperation));
36
36
  let promise;
37
37
  act(() => {
38
- promise = result.current.execute({}, {});
38
+ promise = result.current[0]({}, {});
39
39
  });
40
- expect(result.current.state.state).toBe('loading');
40
+ expect(result.current[1].state.state).toBe('loading');
41
41
  // @ts-expect-error 2454
42
42
  const newState = await promise;
43
43
  expect(newState.state).toBe('failure');
44
44
  assert(newState.state === 'failure');
45
45
  expect(newState.error).toBe(error);
46
46
  await act(async () => { });
47
- expect(result.current.state).toStrictEqual(newState);
47
+ expect(result.current[1].state).toStrictEqual(newState);
48
48
  });
49
49
  });
@@ -8,10 +8,12 @@ export declare const lazyInitialState: Readonly<{
8
8
  readonly state: "initial";
9
9
  }>;
10
10
  type LazyOperationExecuteReturnType<TResult> = Promise<OperationSuccessState<TResult> | OperationFailureState>;
11
- export interface UseLazyOperationReturnType<TVariables, TResult, TRequestContext extends RequestContext> {
12
- execute: (variables: TVariables, requestContext: TRequestContext) => LazyOperationExecuteReturnType<TResult>;
13
- state: LazyOperationState<TResult>;
14
- reset: () => void;
15
- }
11
+ export type UseLazyOperationReturnType<TVariables, TResult, TRequestContext extends RequestContext> = [
12
+ (variables: TVariables, requestContext: TRequestContext) => LazyOperationExecuteReturnType<TResult>,
13
+ {
14
+ state: LazyOperationState<TResult>;
15
+ reset: () => void;
16
+ }
17
+ ];
16
18
  export declare function useLazyOperation<T extends SyncOperation<unknown, unknown>, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T): UseLazyOperationReturnType<OperationVariables<T>, OperationResult<T>, TRequestContext>;
17
19
  export {};
@@ -19,9 +19,8 @@ export function useLazyOperation(executor, operation) {
19
19
  setState(loadingState);
20
20
  return execute(executor, operation, variables, requestContext, setState);
21
21
  }, [setState, executor, operation]);
22
- return {
23
- state,
24
- execute: executeCallback,
25
- reset: () => setState(lazyInitialState)
26
- };
22
+ return [
23
+ executeCallback,
24
+ { state, reset: () => setState(lazyInitialState) }
25
+ ];
27
26
  }