3d-animation/hooks/useAssetLoader.ts
2026-06-07 06:35:39 +08:00

24 lines
No EOL
535 B
TypeScript

'use client';
import { useState, useEffect } from 'react';
export function useAssetLoader(url: string) {
const [asset, setAsset] = useState<any>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);
useEffect(() => {
fetch(url)
.then((res) => res.json())
.then((data) => {
setAsset(data);
setLoading(false);
})
.catch(() => {
setError(true);
setLoading(false);
});
}, [url]);
return { asset, loading, error };
}