@ic-reactor/react 0.2.5 → 0.2.6
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 +13 -9
- package/dist/index.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -30,31 +30,35 @@ Here's a simple example to get you started:
|
|
|
30
30
|
|
|
31
31
|
First, create an actor declaration file:
|
|
32
32
|
|
|
33
|
-
```
|
|
34
|
-
// store.
|
|
35
|
-
import { canisterId,
|
|
33
|
+
```ts
|
|
34
|
+
// store.ts
|
|
35
|
+
import { canisterId, idlFactory, actor } from "declaration/actor"
|
|
36
36
|
import { createReActor } from "@ic-reactor/core"
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
type Actor = typeof actor
|
|
39
|
+
|
|
40
|
+
export const { useActorStore, useQueryCall } = createReActor<Actor>({
|
|
41
|
+
canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
42
|
+
idlFactory,
|
|
43
|
+
host: "https://localhost:4943",
|
|
44
|
+
})
|
|
41
45
|
```
|
|
42
46
|
|
|
43
47
|
Then, use the `useQueryCall` hook to call your canister method:
|
|
44
48
|
|
|
45
49
|
```jsx
|
|
46
|
-
// Balance.
|
|
50
|
+
// Balance.tsx
|
|
47
51
|
import { useQueryCall } from "./store"
|
|
48
52
|
|
|
49
53
|
const Balance = ({ principal }) => {
|
|
50
|
-
const {
|
|
54
|
+
const { call, data, loading, error } = useQueryCall({
|
|
51
55
|
functionName: "get_balance",
|
|
52
56
|
args: [principal],
|
|
53
57
|
})
|
|
54
58
|
|
|
55
59
|
return (
|
|
56
60
|
<div>
|
|
57
|
-
<button onClick={() =>
|
|
61
|
+
<button onClick={() => call()} disabled={loading}>
|
|
58
62
|
{loading ? "Loading..." : "Refresh"}
|
|
59
63
|
</button>
|
|
60
64
|
{loading && <p>Loading...</p>}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const createReActor: <A extends unknown>(options: ReActorOptions)
|
|
|
5
5
|
useMethodFields: () => import("@ic-reactor/store").ReActorMethodField<A>[];
|
|
6
6
|
useMethodField: (functionName: keyof A & string) => import("@ic-reactor/store").ReActorMethodField<A> | undefined;
|
|
7
7
|
useActorStore: () => {
|
|
8
|
-
initialize: (agentOptions?: import("@dfinity/agent").HttpAgentOptions | undefined, identity?: import("@ic-reactor/store").Identity | undefined) => void
|
|
8
|
+
initialize: (agentOptions?: import("@dfinity/agent").HttpAgentOptions | undefined, identity?: import("@ic-reactor/store").Identity | undefined) => Promise<void>;
|
|
9
9
|
actor: A | null;
|
|
10
10
|
initialized: boolean;
|
|
11
11
|
initializing: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "A React library for interacting with Dfinity actors",
|
|
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/store": "^0.2.
|
|
38
|
+
"@ic-reactor/store": "^0.2.5",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": ">=16.8",
|
|
49
49
|
"zustand": "4.4"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "abd0749e41ce35c4cc213093a6030128330fbf28"
|
|
52
52
|
}
|