当innerBlock更改时,Gutenberg更新ParentBlock

时间:2019-01-22 21:23:20

标签: wordpress-gutenberg gutenberg-blocks

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

1 个答案:

答案 0 :(得分: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 ); 
相关问题