将自定义注册块导入古腾堡中的另一个自定义块
Import custom registered block to another custom block in Gutenberg
我创建了一个自定义按钮块并想在其他块中使用它,例如 CTA 或图标功能。
我在一些插件中看到这样的代码,导出注册块:
export default registerBlockType( 'name_space/button', {
但现在我想将它导入另一个块以备将来使用。类似的东西:
import CustomButton from '../custom-button/block';
我试过将它包含在另一个块的 edit
方法中 {CustomButton}
和 <CustomButton />
。但是每次我得到一个错误。
我有办法做这样的事情吗?
您可以 InnerBlocks 在您的块中使用核心块或自定义块。请记住,它只能在一个块内使用一次。
我创建了一个自定义按钮块并想在其他块中使用它,例如 CTA 或图标功能。 我在一些插件中看到这样的代码,导出注册块:
export default registerBlockType( 'name_space/button', {
但现在我想将它导入另一个块以备将来使用。类似的东西:
import CustomButton from '../custom-button/block';
我试过将它包含在另一个块的 edit
方法中 {CustomButton}
和 <CustomButton />
。但是每次我得到一个错误。
我有办法做这样的事情吗?
您可以 InnerBlocks 在您的块中使用核心块或自定义块。请记住,它只能在一个块内使用一次。