humanmade / humanmade/block-editor-components

useMediaSrc

Open
#303 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.