@ic-reactor/react 1.10.4 → 1.11.1

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.
@@ -125,7 +125,7 @@ const actorHooks = (actorManager) => {
125
125
  const replaceArgs = eventOrReplaceArgs instanceof Array ? eventOrReplaceArgs : args;
126
126
  const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
127
127
  setSharedState({ data, error: undefined, loading: false });
128
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
128
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess((0, utils_1.createCompiledResult)(data));
129
129
  onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
130
130
  return data;
131
131
  }
@@ -142,7 +142,8 @@ const actorHooks = (actorManager) => {
142
142
  throw error;
143
143
  }
144
144
  }), [args, functionName, options, onError, onLoading, onSuccess, throwOnError]);
145
- return Object.assign({ call, reset, requestKey }, sharedState);
145
+ const compileResult = React.useCallback(() => (0, utils_1.createCompiledResult)(sharedState === null || sharedState === void 0 ? void 0 : sharedState.data), [sharedState === null || sharedState === void 0 ? void 0 : sharedState.data]);
146
+ return Object.assign({ call, reset, compileResult, requestKey }, sharedState);
146
147
  };
147
148
  const useQueryCall = (_a) => {
148
149
  var { refetchOnMount = true, refetchInterval = false } = _a, rest = __rest(_a, ["refetchOnMount", "refetchInterval"]);
@@ -157,7 +158,7 @@ const actorHooks = (actorManager) => {
157
158
  call();
158
159
  }
159
160
  else if (refetchOnMount && state.data !== undefined) {
160
- (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, state.data);
161
+ (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, (0, utils_1.createCompiledResult)(state.data));
161
162
  }
162
163
  return () => clearInterval(intervalId.current);
163
164
  }, [refetchInterval, refetchOnMount]);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CallConfig } from "@dfinity/agent";
3
- import type { IDL, ActorState, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService, AuthState, HttpAgent, AgentState, BaseActor, MethodAttributes } from "../types";
3
+ import type { IDL, ActorState, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService, AuthState, HttpAgent, AgentState, BaseActor, MethodAttributes, CompiledResult } from "../types";
4
4
  export interface AgentHooksReturnType {
5
5
  useAgent: () => HttpAgent | undefined;
6
6
  useAgentState: () => AgentState;
@@ -42,23 +42,25 @@ export type UseActorStore<A> = <T>(callback?: (state: ActorState<A>) => T) => T;
42
42
  export interface UseActorStateReturnType extends Omit<ActorState, "methodState"> {
43
43
  canisterId: string;
44
44
  }
45
+ export type UseSharedCallState<A, M extends FunctionName<A>> = {
46
+ data: ActorMethodReturnType<A[M]> | undefined;
47
+ error: Error | undefined;
48
+ loading: boolean;
49
+ };
45
50
  export interface UseSharedCallParameters<A, M extends FunctionName<A>> extends CallConfig {
46
51
  functionName: M;
47
52
  args?: ActorMethodParameters<A[M]>;
48
53
  onLoading?: (loading: boolean) => void;
49
54
  onError?: (error: Error | undefined) => void;
50
- onSuccess?: (data: ActorMethodReturnType<A[M]> | undefined) => void;
55
+ onSuccess?: (data: CompiledResult<ActorMethodReturnType<A[M]>> | undefined) => void;
51
56
  throwOnError?: boolean;
57
+ compileResult?: boolean;
52
58
  }
53
- export type UseSharedCallState<A, M extends FunctionName<A>> = {
54
- data: ActorMethodReturnType<A[M]> | undefined;
55
- error: Error | undefined;
56
- loading: boolean;
57
- };
58
59
  export interface UseSharedCallReturnType<A, M extends FunctionName<A> = FunctionName<A>> extends UseSharedCallState<A, M> {
59
60
  requestKey: string;
60
61
  reset: () => void;
61
- call: (eventOrReplaceArgs?: React.MouseEvent | ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]> | undefined>;
62
+ compileResult: () => CompiledResult<ActorMethodReturnType<A[M]>>;
63
+ call: (eventOrReplaceArgs?: ActorMethodParameters<A[M]> | React.MouseEvent) => Promise<ActorMethodReturnType<A[M]> | undefined>;
62
64
  }
63
65
  export type UseSharedCall<A> = <M extends FunctionName<A>>(params: UseSharedCallParameters<A, M>) => UseSharedCallReturnType<A, M>;
64
66
  export interface UseQueryCallParameters<A, M extends FunctionName<A>> extends UseSharedCallParameters<A, M> {
@@ -84,7 +86,7 @@ export interface UseMethodReturnType<A, M extends FunctionName<A> = FunctionName
84
86
  validateArgs: (args?: ActorMethodParameters<A[M]> | undefined) => boolean;
85
87
  visit: VisitService<A>[M];
86
88
  reset: () => void;
87
- call: (eventOrReplaceArgs?: React.MouseEvent | ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]> | undefined>;
89
+ call: (eventOrReplaceArgs?: ActorMethodParameters<A[M]> | React.MouseEvent) => Promise<ActorMethodReturnType<A[M]> | undefined>;
88
90
  }
89
91
  export type UseMethod<A> = <M extends FunctionName<A>>(args: UseMethodParameters<A, M>) => UseMethodReturnType<A, M>;
90
92
  export type UseVisitMethod<A> = <M extends FunctionName<A>>(functionName: M) => VisitService<A>[M];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.10.4",
3
+ "version": "1.11.1",
4
4
  "description": "A React library for interacting with Internet Computer canisters",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "node": ">=10"
36
36
  },
37
37
  "dependencies": {
38
- "@ic-reactor/core": "^1.10.3",
38
+ "@ic-reactor/core": "^1.11.0",
39
39
  "zustand-utils": "^1.3"
40
40
  },
41
41
  "peerDependencies": {
@@ -47,5 +47,5 @@
47
47
  "react": ">=16.8",
48
48
  "zustand": "4.5"
49
49
  },
50
- "gitHead": "c77fe50f1916752c99b0a0658158aa7fd9a8e03c"
50
+ "gitHead": "d4eedb456c14717255f56ad5b4993622fc548567"
51
51
  }