Я недавно задал вопрос на ту же тему .Там я сам нашел проблему.Но, к сожалению, я получил новую ошибку:
TypeError: Cannot read property 'innerBlocks' of null
at InnerBlocks.synchronizeBlocksWithTemplate (script.build.js?ver=1:149405)
at InnerBlocks.componentDidMount (script.build.js?ver=1:149366)
at zc (react-dom.min.js?ver=16.6.3:146)
at wc (react-dom.min.js?ver=16.6.3:138)
at fa (react-dom.min.js?ver=16.6.3:137)
at ng (react-dom.min.js?ver=16.6.3:149)
at Se (react-dom.min.js?ver=16.6.3:40)
Итак, я попробовал его с тем же кодом, но у меня не получается:
const {registerBlockType} = wp.blocks;
const {InspectorControls, RichText, MediaUpload} = wp.editor;
import {TextControl} from '@wordpress/components';
import {InnerBlocks} from '@wordpress/editor';
let blockStyle = {
marginTop: "25px",
marginBottom: "25px;"
};
registerBlockType('myself/test-component', {
title: 'Test component',
icon: 'editor-insertmore',
category: 'common',
attributes: {
title: {
type: 'string'
}
},
edit(props) {
const {setAttributes, attributes} = props;
function setTitle(changes) {
setAttributes({
title: changes
})
}
return (
<div style={blockStyle}>
<TextControl
placeholder="Titel"
value={attributes.title}
onChange={setTitle}
/>
<InnerBlocks
templateLock={false}
renderAppender={(
() => <InnerBlocks.ButtonBlockAppender/>
)}
/>
</div>
)
},
save(props) {
const {attributes, className} = props;
return (
<div style={blockStyle}>
<InnerBlocks.Content/>
</div>
);
}
});
Затем я проверилвстроенный файл script.js, который встроен как плагин.Там мы имеем следующую ситуацию, что this.props.block
равно null
.
key: "componentDidMount",
value: function componentDidMount() {
var innerBlocks = this.props.block.innerBlocks; // only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists
if (innerBlocks.length === 0 || this.getTemplateLock() === 'all') {
this.synchronizeBlocksWithTemplate();
}
if (this.state.templateInProcess) {
this.setState({
templateInProcess: false
});
}
}
ОБНОВЛЕНИЕ
Переменная this.props
имеет следующие переменные:

Кто-нибудь сталкивается с той же проблемой или есть обходной путь для этого?