I've been using a variation of the following to convert an attachment ID to a URL:
function useMediaSrc( id ) {
const url = useSelect(
( select ) => {
const media = select( 'core' ).getMedia( id, { context: 'view' } );
if ( ! media ) {
return undefined;
}
return media.source_url;
},
[ id ]
);
return url;
}
It'd be good to have this in the hooks available
I've been using a variation of the following to convert an attachment ID to a URL:
It'd be good to have this in the hooks available