当innerBlock更改时,Gutenberg更新ParentBlock

问题描述 投票:2回答:1

我创建了一个gutenberg滑块块和一个名为slide的子块。我想在每次更新幻灯片时更新滑块。我使用innerBlock(幻灯片)中的componentDidUpdate(),但我不知道如何从那里访问父级。

wordpress-gutenberg gutenberg-blocks
1个回答
0
投票

您可以使用以下代码访问父块:

// Get child block ID
const parentClientId = select( 'core/block-editor' ).getBlockHierarchyRootClientId( props.clientId );

// Get parent attributes using child block ID
// @see https://github.com/WordPress/gutenberg/issues/9032
const { iconStyle, iconSize, iconColor } = select( 'core/block-editor' ).getBlockAttributes( parentClientId ); 
© www.soinside.com 2019 - 2024. All rights reserved.