我正在扩展组块。我遇到的问题是,如果我选择一个选项,后端不会发生任何变化。但如果我再次更改它,它将显示上一个选定选项的类。我认为const组合导致了这个问题。我真的不知道如何正确地组合多个属性。你能帮帮我吗?
/**
* Create HOC to add group control to inspector controls of block.
*/
const withGroupControl = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
// Do nothing if it\'s another block than our defined ones.
if ( ! enableGroupControlOnBlocks.includes( props.name ) ) {
return (
<BlockEdit { ...props } />
);
}
const { width } = props.attributes;
const { color } = props.attributes;
const { highlight } = props.attributes;
const combo = width + \' \' + color + \' \' + highlight;
if ( combo ) {
props.attributes.className = `${ combo }`;
}
return (
<Fragment>
<BlockEdit { ...props } />
<InspectorControls>
<PanelBody
title={ \'Functions\' }
initialOpen={ true }
>
<SelectControl
label={ \'Width settings\' }
value={ width }
options={ groupWidthControlOptions }
onChange={ ( selectedWidthOption ) => {
props.setAttributes( {
width: selectedWidthOption,
} );
} }
/>
<SelectControl
label={ \'Color settings\' }
value={ color }
options={ groupColorControlOptions }
onChange={ ( selectedColorOption ) => {
props.setAttributes( {
color: selectedColorOption,
} );
} }
/>
<SelectControl
label={ \'Highlight settings\' }
value={ highlight }
options={ groupHighlightControlOptions }
onChange={ ( selectedHighlightOption ) => {
props.setAttributes( {
highlight: selectedHighlightOption,
} );
} }
/>
</PanelBody>
</InspectorControls>
</Fragment>
);
};
}, \'withGroupControl\' );
addFilter( \'editor.BlockEdit\', \'ww-group/with-group-control\', withGroupControl );