块编辑器中的所有当前数据都存储在数据存储中。如果单击“保存”按钮,该数据将通过REST API发送到数据库。您可以从存储中选择数据并订阅更改。
// Create a higher-order component that updates automatically when featured image changes.
const applyWithSelect = withSelect( ( select ) => {
const { getMedia } = select( \'core\' );
const { getEditedPostAttribute } = select( \'core/editor\' );
const featuredImageId = getEditedPostAttribute( \'featured_media\' );
return {
media: featuredImageId ? getMedia( featuredImageId ) : null,
featuredImageId,
};
} );
export default compose( [
applyWithSelect,
] )( MyCustomBlockEdit );
source