Skip to content

useMediaSrc #303

Description

@tomjn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    javascriptPull requests that update Javascript code

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions