Do not return empty asset from useMediaAsset

This commit is contained in:
Daniel Lautzenheiser 2023-01-11 10:55:22 -05:00
parent 40693c593c
commit 32298b46b7

View File

@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { getAsset } from '@staticcms/core/actions/media'; import { emptyAsset, getAsset } from '@staticcms/core/actions/media';
import { useAppDispatch } from '@staticcms/core/store/hooks'; import { useAppDispatch } from '@staticcms/core/store/hooks';
import { isNotEmpty } from '../util/string.util'; import { isNotEmpty } from '../util/string.util';
@ -21,8 +21,10 @@ export default function useMediaAsset<T extends Field>(
} }
const fetchMedia = async () => { const fetchMedia = async () => {
const asset = (await dispatch(getAsset<T>(collection, entry, url, field)))?.toString() ?? ''; const asset = await dispatch(getAsset<T>(collection, entry, url, field));
setAssetSource(asset); if (asset !== emptyAsset) {
setAssetSource(asset?.toString() ?? '');
}
}; };
fetchMedia(); fetchMedia();