@ic-reactor/react 0.1.1 → 0.2.0
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/README.md +4 -17
- package/dist/index.d.ts +10 -4
- package/dist/index.js +9 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,21 +35,11 @@ First, create an actor declaration file:
|
|
|
35
35
|
import { canisterId, createActor } from "declaration/actor"
|
|
36
36
|
import { createReActor } from "@ic-reactor/core"
|
|
37
37
|
|
|
38
|
-
export const {
|
|
38
|
+
export const { useQueryCall, useUpdateCall } = createReActor((agent) =>
|
|
39
39
|
createActor(canisterId, { agent })
|
|
40
40
|
)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Wrap your app with the `ReActorProvider` component:
|
|
44
|
-
|
|
45
|
-
```jsx
|
|
46
|
-
// App.jsx
|
|
47
|
-
|
|
48
|
-
<ReActorProvider>
|
|
49
|
-
<Balance principal={principal} />
|
|
50
|
-
</ReActorProvider>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
43
|
Then, use the `useQueryCall` hook to call your canister method:
|
|
54
44
|
|
|
55
45
|
```jsx
|
|
@@ -81,10 +71,11 @@ export default Balance
|
|
|
81
71
|
|
|
82
72
|
The library provides various hooks and utilities for interacting with IC actors:
|
|
83
73
|
|
|
74
|
+
- `useActorStore`: Hook for managing actor states.
|
|
75
|
+
- `useAuthStore` Hook for managing authentication states.
|
|
76
|
+
- `useAuthClient`: Hook for managing authentication with the IC blockchain.
|
|
84
77
|
- `useQueryCall`: Hook for querying data from an actor.
|
|
85
78
|
- `useUpdateCall`: Hook for updating data in an actor.
|
|
86
|
-
- `useReActor`: Hook to access the global actor state.
|
|
87
|
-
- `ReActorProvider`: React context provider for ReActor state.
|
|
88
79
|
- Additional hooks for handling loading, errors, authentication, and more.
|
|
89
80
|
|
|
90
81
|
For detailed API usage and options, please refer to the [documentation](#).
|
|
@@ -96,7 +87,3 @@ Contributions to `@ic-reactor/react` are welcome! Please read our [contributing
|
|
|
96
87
|
## License
|
|
97
88
|
|
|
98
89
|
`@ic-reactor/react` is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
This README provides a foundational overview of your package. You should expand it with more detailed documentation, examples, and links to additional resources or documentation as needed. Replace placeholders with actual information and links relevant to your project.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import type { HttpAgent } from "@dfinity/agent";
|
|
2
1
|
import { AuthClientLoginOptions } from "@dfinity/auth-client";
|
|
3
2
|
import type { ActorSubclass, ReActorAuthStore, ReActorOptions } from "@ic-reactor/store";
|
|
4
3
|
export type ReActorContextType<A = ActorSubclass<any>> = ReActorAuthStore<A>;
|
|
5
|
-
export declare const createReActor: <A extends unknown>(
|
|
6
|
-
useActorStore: () =>
|
|
4
|
+
export declare const createReActor: <A extends unknown>(options: ReActorOptions) => {
|
|
5
|
+
useActorStore: () => {
|
|
6
|
+
initialize: (agentOptions?: import("@dfinity/agent").HttpAgentOptions | undefined, identity?: import("@ic-reactor/store").Identity | undefined) => void;
|
|
7
|
+
actor: A | null;
|
|
8
|
+
initialized: boolean;
|
|
9
|
+
initializing: boolean;
|
|
10
|
+
error: Error | undefined;
|
|
11
|
+
methodState: import("@ic-reactor/store").ReActorMethodStates<A>;
|
|
12
|
+
};
|
|
7
13
|
useAuthStore: () => import("@ic-reactor/store").ReActorAuthState<A>;
|
|
8
14
|
useQueryCall: <M extends keyof A>({ autoRefresh, refreshInterval, disableInitialCall, ...rest }: import("./types").ReActorUseQueryArgs<A, M>) => {
|
|
9
15
|
data: import("@ic-reactor/store").ExtractReActorMethodReturnType<A[M]> | undefined;
|
|
@@ -21,7 +27,7 @@ export declare const createReActor: <A extends unknown>(actorInitializer: (agent
|
|
|
21
27
|
authClient: import("@dfinity/auth-client").AuthClient | null;
|
|
22
28
|
authenticated: boolean;
|
|
23
29
|
authenticating: boolean;
|
|
24
|
-
identity: import("@
|
|
30
|
+
identity: import("@ic-reactor/store").Identity | null;
|
|
25
31
|
login: (options?: AuthClientLoginOptions) => Promise<void>;
|
|
26
32
|
logout: (options?: {
|
|
27
33
|
returnTo?: string;
|
package/dist/index.js
CHANGED
|
@@ -14,18 +14,17 @@ const store_1 = require("@ic-reactor/store");
|
|
|
14
14
|
const react_1 = require("react");
|
|
15
15
|
const zustand_1 = require("zustand");
|
|
16
16
|
const hooks_1 = require("./hooks");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: "http://localhost:4943",
|
|
22
|
-
};
|
|
23
|
-
const createReActor = (actorInitializer, options = {}) => {
|
|
24
|
-
const optionsWithDefaults = Object.assign(Object.assign({}, defaultCreateReActorOptions), options);
|
|
25
|
-
const { callMethod, authenticate, authStore, actorStore } = (0, store_1.createReActorStore)((agent) => actorInitializer(agent), optionsWithDefaults);
|
|
17
|
+
const isLocal = (process === null || process === void 0 ? void 0 : process.env.NODE_ENV) === "development" ||
|
|
18
|
+
(process === null || process === void 0 ? void 0 : process.env.DFX_NETWORK) === "local";
|
|
19
|
+
const createReActor = (options) => {
|
|
20
|
+
const { callMethod, unsubscribe, initialize, authenticate, authStore, actorStore, } = (0, store_1.createReActorStore)(Object.assign(Object.assign({ isLocal }, options), { initializeOnMount: false }));
|
|
26
21
|
const useActorStore = () => {
|
|
27
22
|
const actorState = (0, zustand_1.useStore)(actorStore, (state) => state);
|
|
28
|
-
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
initialize();
|
|
25
|
+
return unsubscribe;
|
|
26
|
+
}, []);
|
|
27
|
+
return Object.assign(Object.assign({}, actorState), { initialize });
|
|
29
28
|
};
|
|
30
29
|
const useAuthStore = () => {
|
|
31
30
|
const authState = (0, zustand_1.useStore)(authStore, (state) => state);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A React library for interacting with Dfinity actors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@dfinity/candid": "0.20",
|
|
41
41
|
"@dfinity/identity": "^0.20",
|
|
42
42
|
"@dfinity/principal": "^0.20",
|
|
43
|
-
"@ic-reactor/store": "^0.
|
|
43
|
+
"@ic-reactor/store": "^0.2.0",
|
|
44
44
|
"zustand": "4.4",
|
|
45
45
|
"zustand-utils": "^1.3"
|
|
46
46
|
},
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"@peculiar/webcrypto": "1.4",
|
|
49
49
|
"react": ">=16.8"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "8499f295b9e20d1dc12bd4f0a33927bfce54c23a"
|
|
52
52
|
}
|