@ic-reactor/react 1.8.1 → 1.8.3

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.
@@ -82,7 +82,7 @@ function createActorContext(contextConfig = {}) {
82
82
  const { canisterId: defaultCanisterId } = contextConfig, defaultConfig = __rest(contextConfig, ["canisterId"]);
83
83
  const ActorContext = react_1.default.createContext(null);
84
84
  const ActorProvider = (_a) => {
85
- var { children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Fetching canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "fetchingComponent", "canisterId", "errorComponent", "loadingComponent", "authenticatingComponent"]);
85
+ var { children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Loading canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "fetchingComponent", "canisterId", "errorComponent", "loadingComponent", "authenticatingComponent"]);
86
86
  if (!canisterId) {
87
87
  throw new Error("canisterId is required");
88
88
  }
@@ -91,15 +91,19 @@ function createActorContext(contextConfig = {}) {
91
91
  const useInitializeActor = react_1.default.useCallback(() => {
92
92
  return initializeActor;
93
93
  }, [initializeActor]);
94
+ const ActorChildren = ({ useActorState }) => {
95
+ const { initializing, initialized, error } = useActorState();
96
+ return initializing
97
+ ? loadingComponent
98
+ : initialized
99
+ ? children
100
+ : error
101
+ ? errorComponent(error.message)
102
+ : null;
103
+ };
94
104
  return (react_1.default.createElement(ActorContext.Provider, { value: Object.assign(Object.assign({}, hooks), { useInitializeActor }) },
95
105
  fetchingComponent,
96
- hooks === null
97
- ? fetchError
98
- ? errorComponent(fetchError)
99
- : authenticating
100
- ? authenticatingComponent
101
- : loadingComponent
102
- : children));
106
+ hooks === null ? (fetchError ? (errorComponent(fetchError)) : authenticating ? (authenticatingComponent) : (loadingComponent)) : (react_1.default.createElement(ActorChildren, { useActorState: hooks.useActorState }, children))));
103
107
  };
104
108
  ActorProvider.displayName = "ActorProvider";
105
109
  const ActorHookProvider = ({ hooks, children, }) => {
@@ -26,3 +26,6 @@ export interface CreateActorContextParameters extends Omit<ActorManagerParameter
26
26
  idlFactory?: IDL.InterfaceFactory;
27
27
  disableAutoFetch?: boolean;
28
28
  }
29
+ export interface ActorChildrenProps extends React.PropsWithChildren {
30
+ useActorState: ActorHooksReturnType["useActorState"];
31
+ }
@@ -77,6 +77,7 @@ const actorHooks = (actorManager) => {
77
77
  return useActorStore((state) => ({
78
78
  name: state.name,
79
79
  error: state.error,
80
+ version: state.version,
80
81
  initialized: state.initialized,
81
82
  initializing: state.initializing,
82
83
  canisterId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
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.8.0",
38
+ "@ic-reactor/core": "^1.8.1",
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": "7d1a090ce85775c0f033a75e3ddfb127b70a540b"
50
+ "gitHead": "95a5f50cb3a15e2167cd50b82efb09dfdd6661f1"
51
51
  }