I am trying to make a simple Gutenberg block which implements <InspectorControls>
, but I’m getting a React error no matter which I component I use.
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
}
} );
I’m using the ‘create-guten-block’ development kit.
Error:
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)
3 Answers
TextControl
is from wp.components
not wp.blocks
.
const {
registerBlockType,
RichText,
AlignmentToolbar,
BlockControls,
InspectorControls,
} = wp.blocks;
const {
TextControl
} = wp.components;
Changing that I was able to get your block to work fine instead of error in Gutenberg 2.2.0
.