@ic-reactor/react 1.12.1 → 1.12.2
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/dist/helpers/actorHooks.js +14 -3
- package/package.json +2 -2
|
@@ -117,13 +117,18 @@ const actorHooks = (actorManager) => {
|
|
|
117
117
|
var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess"]);
|
|
118
118
|
const requestKey = React.useMemo(() => (0, utils_1.generateRequestHash)(args), [args]);
|
|
119
119
|
const [sharedState, setSharedState] = useMethodState(functionName, requestKey);
|
|
120
|
-
const
|
|
120
|
+
const latestDataRef = React.useRef();
|
|
121
|
+
const reset = React.useCallback(() => {
|
|
122
|
+
updateMethodState(functionName, requestKey, DEFAULT_STATE);
|
|
123
|
+
latestDataRef.current = undefined;
|
|
124
|
+
}, [functionName, requestKey]);
|
|
121
125
|
const call = React.useCallback((eventOrReplaceArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
126
|
setSharedState({ error: undefined, loading: true });
|
|
123
127
|
onLoading === null || onLoading === void 0 ? void 0 : onLoading(true);
|
|
124
128
|
try {
|
|
125
129
|
const replaceArgs = eventOrReplaceArgs instanceof Array ? eventOrReplaceArgs : args;
|
|
126
130
|
const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
|
|
131
|
+
latestDataRef.current = data;
|
|
127
132
|
setSharedState({ data, error: undefined, loading: false });
|
|
128
133
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess((0, utils_1.createCompiledResult)(data));
|
|
129
134
|
onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
|
|
@@ -132,6 +137,7 @@ const actorHooks = (actorManager) => {
|
|
|
132
137
|
catch (error) {
|
|
133
138
|
// eslint-disable-next-line no-console
|
|
134
139
|
console.error(`Error calling method ${functionName}:`, error);
|
|
140
|
+
latestDataRef.current = undefined;
|
|
135
141
|
setSharedState({
|
|
136
142
|
error: error,
|
|
137
143
|
loading: false,
|
|
@@ -142,8 +148,13 @@ const actorHooks = (actorManager) => {
|
|
|
142
148
|
throw error;
|
|
143
149
|
}
|
|
144
150
|
}), [args, functionName, options, onError, onLoading, onSuccess, throwOnError]);
|
|
145
|
-
const compileResult =
|
|
146
|
-
|
|
151
|
+
const compileResult = () => {
|
|
152
|
+
return (0, utils_1.createCompiledResult)(latestDataRef.current || (sharedState === null || sharedState === void 0 ? void 0 : sharedState.data));
|
|
153
|
+
};
|
|
154
|
+
return Object.assign({ call,
|
|
155
|
+
reset,
|
|
156
|
+
compileResult,
|
|
157
|
+
requestKey }, sharedState);
|
|
147
158
|
};
|
|
148
159
|
const useQueryCall = (_a) => {
|
|
149
160
|
var { refetchOnMount = true, refetchInterval = false } = _a, rest = __rest(_a, ["refetchOnMount", "refetchInterval"]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.2",
|
|
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",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"react": ">=16.8",
|
|
48
48
|
"zustand": "4.5"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "83eaedfd96a494e188b0b35366761800ea3be186"
|
|
51
51
|
}
|