Skip to content

Commit 6853e15

Browse files
committed
Remove axios-hooks from demo
1 parent 5993f80 commit 6853e15

3 files changed

Lines changed: 24 additions & 49 deletions

File tree

apps/demo/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"dependencies": {
1616
"@h5web/app": "workspace:*",
1717
"@h5web/h5wasm": "workspace:*",
18-
"axios-hooks": "5.1.1",
1918
"h5wasm-plugins": "0.3.0",
2019
"modern-normalize": "3.0.1",
2120
"react": "18.3.1",

apps/demo/src/h5wasm/UrlForm.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import useAxios from 'axios-hooks';
2-
import { type FormEvent, useCallback, useEffect } from 'react';
1+
import { createBasicFetcher } from '@h5web/app';
2+
import { type FormEvent, useCallback, useEffect, useState } from 'react';
33
import { FiLoader } from 'react-icons/fi';
44
import { useSearchParams } from 'wouter';
55

6+
import { FetcherError } from '../../../../packages/app/src/providers/utils';
67
import { type RemoteFile } from './models';
78
import styles from './UrlForm.module.css';
89

10+
const fetcher = createBasicFetcher();
11+
912
interface Props {
1013
onLoad: (h5File: RemoteFile) => void;
1114
}
@@ -16,20 +19,29 @@ function UrlForm(props: Props) {
1619
const [searchParams, setSearchParams] = useSearchParams();
1720
const url = searchParams.get('url') || '';
1821

19-
const [{ loading, error }, execute] = useAxios<ArrayBuffer>(
20-
{ url, responseType: 'arraybuffer' },
21-
{ manual: true },
22-
);
22+
const [loading, setLoading] = useState(false);
23+
const [error, setError] = useState<unknown>();
2324

2425
const fetchFile = useCallback(async () => {
25-
if (url) {
26-
const { data } = await execute();
26+
if (!url) {
27+
return;
28+
}
29+
30+
setLoading(true);
31+
setError(undefined);
32+
33+
try {
34+
const buffer = await fetcher(url, {});
2735
onLoad({
2836
filename: url.slice(url.lastIndexOf('/') + 1),
29-
buffer: data,
37+
buffer,
3038
});
39+
} catch (error_) {
40+
setError(error_);
41+
} finally {
42+
setLoading(false);
3143
}
32-
}, [url, execute, onLoad]);
44+
}, [url, onLoad]);
3345

3446
useEffect(() => {
3547
void fetchFile();
@@ -77,9 +89,9 @@ function UrlForm(props: Props) {
7789
</form>
7890
{error && (
7991
<p className={styles.hint} role="alert">
80-
{error.isAxiosError
92+
{error instanceof FetcherError
8193
? 'Sorry, your file could not be fetched'
82-
: `An error occured: ${error.message}`}
94+
: `An error occured${error instanceof Error ? `: ${error.message}` : ''}`}
8395
</p>
8496
)}
8597
</>

pnpm-lock.yaml

Lines changed: 0 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)