So I was following along with the “Advanced WordPress Block Development” -Example – Layout Switcher.
I was at the “Creating And Inserting a Block with the Data API ” video and keep running into the error of insertBlocks is not defined
for the sake of simplicity here is the call from the SwitcherControls.JS file. (Ignoring the button component for this)
What am I missing to cause this error?? Also I can provide more code if this isn’t enough.
const { __ } = wp.i18n;
const { Fragment } = wp.element;
const { Button, Icon, PanelBody, PanelRow } = wp.components;
const { withSelect, dispatch } = wp.data;
const SwitcherControls = ({ blocks, icons, myBlock }) => {
let blockIds = blocks.map( block => block.clientId);
return (
<Fragment>
<PanelBody
title={__("Layout Choices", "madisonadvblocks") }
opened
>
<PanelRow
className="layout-switcher"
>
<button onClick={() => insertBlocks(myBlock)}>
<Icon icon={icons.hero} />
<span>{__("Hero", "madisonadvblocks")}</span>
</button>
</PanelRow>
</PanelBody>
</Fragment>
)
}
export default withSelect(select => {
return {
blocks: select("core/block-editor").getBlocks()
}
})(SwitcherControls);