WordPress (PHP) has a lot of functionality to retrieve the post featured image (post thumbnails). However I can't find easy ways to retrieve the post featured image in a dynamic block.
Using PHP:
get_post_thumbnail_id(); // <-- Post Thumbnail ID
Using WordPress REST API:
edit: withSelect( function( select ) {
return {
post_id: select( 'core/editor' ).getCurrentPostId(),
post_type: select( 'core/editor' ).getCurrentPostType()
};
} )( function ( props ) {
wp.apiFetch( { path: '/wp/v2/' + props.post_type + 's/' + props.post_id + '?_embed' } ).then( function( post ) {
console.log( post._embedded["wp:featuredmedia"][0].id ); // <-- Post Thumbnail ID
} );
return el( 'div', null, '[Block Placeholder]' );
} ),