@ar.io/wayfinder-react 1.0.11 → 1.0.12
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 +62 -16
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,7 +20,9 @@ yarn add @ar.io/wayfinder-react @ar.io/wayfinder-core
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
### Initial Setup
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
24
26
|
import {
|
|
25
27
|
WayfinderProvider,
|
|
26
28
|
useWayfinderRequest,
|
|
@@ -32,7 +34,7 @@ import {
|
|
|
32
34
|
} from '@ar.io/wayfinder-core';
|
|
33
35
|
import { ARIO } from '@ar.io/sdk';
|
|
34
36
|
|
|
35
|
-
// Wrap your app with the
|
|
37
|
+
// Wrap your app with the WayfinderProvider
|
|
36
38
|
function App() {
|
|
37
39
|
return (
|
|
38
40
|
<WayfinderProvider
|
|
@@ -49,16 +51,54 @@ function App() {
|
|
|
49
51
|
</WayfinderProvider>
|
|
50
52
|
);
|
|
51
53
|
}
|
|
54
|
+
```
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
### Hooks
|
|
57
|
+
|
|
58
|
+
### useWayfinderUrl
|
|
59
|
+
|
|
60
|
+
Get a dynamic URL for an existing `ar://` URL or legacy `arweave.net`/`arweave.dev` URL.
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { useWayfinderUrl } from '@ar.io/wayfinder-react';
|
|
66
|
+
|
|
67
|
+
function WayfinderImage({ txId }: { txId: string }) {
|
|
68
|
+
const { resolvedUrl, isLoading, error } = useWayfinderUrl({ txId });
|
|
69
|
+
|
|
70
|
+
if (error) {
|
|
71
|
+
return <p>Error resolving URL: {error.message}</p>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (isLoading) {
|
|
75
|
+
return <p>Resolving URL...</p>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<img src={resolvedUrl} alt={txId} />
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### useWayfinderRequest
|
|
60
85
|
|
|
61
|
-
|
|
86
|
+
Fetch the data via wayfinder, and optionally verify the data.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import {
|
|
90
|
+
WayfinderProvider,
|
|
91
|
+
useWayfinderRequest,
|
|
92
|
+
useWayfinderUrl,
|
|
93
|
+
} from '@ar.io/wayfinder-react';
|
|
94
|
+
import {
|
|
95
|
+
NetworkGatewaysProvider,
|
|
96
|
+
LocalStorageGatewaysProvider,
|
|
97
|
+
} from '@ar.io/wayfinder-core';
|
|
98
|
+
import { ARIO } from '@ar.io/sdk';
|
|
99
|
+
|
|
100
|
+
function WayfinderData({ txId }: { txId: string }) {
|
|
101
|
+
const request = useWayfinderRequest();
|
|
62
102
|
const [data, setData] = useState<any>(null);
|
|
63
103
|
const [dataLoading, setDataLoading] = useState(false);
|
|
64
104
|
const [dataError, setDataError] = useState<Error | null>(null);
|
|
@@ -85,14 +125,20 @@ function YourComponent() {
|
|
|
85
125
|
})();
|
|
86
126
|
}, [request, txId]);
|
|
87
127
|
|
|
128
|
+
if (dataError) {
|
|
129
|
+
return <p>Error loading data: {dataError.message}</p>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (dataLoading) {
|
|
133
|
+
return <p>Loading data...</p>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!data) {
|
|
137
|
+
return <p>No data</p>;
|
|
138
|
+
}
|
|
139
|
+
|
|
88
140
|
return (
|
|
89
141
|
<div>
|
|
90
|
-
{urlLoading && <p>Resolving URL...</p>}
|
|
91
|
-
{urlError && <p>Error resolving URL: {urlError.message}</p>}
|
|
92
|
-
{resolvedUrl && <a href={resolvedUrl}>View on WayFinder</a>}
|
|
93
|
-
<br />
|
|
94
|
-
{dataLoading && <p>Loading data...</p>}
|
|
95
|
-
{dataError && <p>Error loading data: {dataError.message}</p>}
|
|
96
142
|
<pre>{data}</pre>
|
|
97
143
|
</div>
|
|
98
144
|
);
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/wayfinder-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "React components for WayFinder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"format:check": "biome format --config-path=../../biome.json"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ar.io/wayfinder-core": "1.2.
|
|
34
|
+
"@ar.io/wayfinder-core": "1.2.1",
|
|
35
35
|
"react": "^18.2.0",
|
|
36
36
|
"react-dom": "^18.2.0"
|
|
37
37
|
},
|