16 lines
365 B
JavaScript
16 lines
365 B
JavaScript
import {Assets} from '@pixi/assets';
|
|
import {useEffect, useState} from 'react';
|
|
|
|
export default function useAsset(source) {
|
|
const [asset, setAsset] = useState();
|
|
useEffect(() => {
|
|
if (Assets.cache.has(source)) {
|
|
setAsset(Assets.get(source));
|
|
}
|
|
else {
|
|
Assets.load(source).then(setAsset);
|
|
}
|
|
}, [setAsset, source]);
|
|
return asset;
|
|
}
|