humanmade / humanmade/block-editor-components
useMediaSrc
Open
javascript
- Dominant language
- JavaScript
- Stars
- 76
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
Assessment
This issue has not been assessed yet.