我想做一个简单的古腾堡积木<InspectorControls>
, 但无论我使用哪个组件,我都会得到一个React错误。
const { __ } = wp.i18n;
const {
registerBlockType,
RichText,
AlignmentToolbar,
BlockControls,
InspectorControls,
TextControl
} = wp.blocks;
registerBlockType( \'gutenberg-examples/example-04-controls-esnext\', {
title: __( \'Example: Controls (esnext)\' ),
icon: \'universal-access-alt\',
category: \'layout\',
attributes: {
content: {
type: \'array\',
selector: \'p\',
},
},
edit: props => {
const {
attributes: {
content,
alignment,
text
},
focus,
className,
setFocus
} = props;
const onChangeContent = newContent => {
props.setAttributes( { content: newContent } );
};
const onChangeAlignment = newAlignment => {
props.setAttributes( { alignment: newAlignment } );
};
const onChangeText = newText => {
props.setAttributes( { text: newText } );
};
return (
<div>
{
!! focus && (
<InspectorControls>
<AlignmentToolbar
value={ alignment }
onChange={ onChangeAlignment }
/>
<TextControl
label=\'Additional CSS Class\'
value={ text }
onChange={ onChangeText }
/>
</InspectorControls>
)
}
<RichText
className={ className }
style={ { textAlign: alignment } }
onChange={ onChangeContent }
value={ content }
focus={ focus }
onFocus={ setFocus }
/>
</div>
);
},
save: props => {
// ignore for now
}
} );
我正在使用“创建guten block”开发工具包。
错误:
react-dom.min.3583f8be.js:162 Error: Minified React error #130; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
at l (react-dom.min.3583f8be.js:12)
at qc (react-dom.min.3583f8be.js:43)
at K (react-dom.min.3583f8be.js:53)
at n (react-dom.min.3583f8be.js:57)
at react-dom.min.3583f8be.js:62
at f (react-dom.min.3583f8be.js:130)
at beginWork (react-dom.min.3583f8be.js:136)
at d (react-dom.min.3583f8be.js:158)
at f (react-dom.min.3583f8be.js:159)
at g (react-dom.min.3583f8be.js:159)
最合适的回答,由SO网友:David Sword 整理而成
TextControl
来自wp.components
不wp.blocks
.
const {
registerBlockType,
RichText,
AlignmentToolbar,
BlockControls,
InspectorControls,
} = wp.blocks;
const {
TextControl
} = wp.components;
更改后,我可以使您的块正常工作,而不是出错
Gutenberg 2.2.0
.