I have a block with some settings that affect the editor only. So not the output. The issue is that when I change these settings, the output doesn’t change. Then WordPress does not detect the change, and does not trigger the “update” button. Next time I open the post the changes to my block-level settings are gone, because they were not saved.
Can I manually trigger the update button from my block?
code
import Edit from "./components/edit/edit"
import PreviewInEditor from "./components/edit/editor-preview";
import BlockSettings from "./components/block-settings/BlockSettings";
import { useBlockProps } from '@wordpress/block-editor';
export default function Editor( props ) {
function update_settings( settings ) {
props.setAttributes( { ...props.attributes, settings } );
}
if( props.isSelected || props.attributes.price_records.length === 0 ) {
return ( <div { ...useBlockProps() }>
<Edit {...props} />
<BlockSettings settings={props.attributes.settings} onChange={update_settings} />
</div> );
} else {
return ( <div { ...useBlockProps() }>
<PreviewInEditor {...props} />
<BlockSettings settings={props.attributes.settings} onChange={update_settings} />
</div>);
}
}