removeBlocks() action not working
-
I need to remove an inner block programmatically. Both the parent and the inner blocks are custom blocks I developed.
So in my
edit.js
file in the parent block, I’m importing the action this way:const { removeBlocks } = useDispatch("core/block-editor");
Then, within my
handleRemoveBlock()
function, I’m doing this:let innerBlocks = [...inner_blocks]; const blockToRemove = innerBlocks.splice(0, 1); console.log(blockToRemove); //This returns the correct block. const clientIds = blockToRemove.map( block => block.clientId ); console.log(clientIds); //This returns the correct clientId. const result = removeBlocks( clientIds ); console.log(result); //This returns PromiseState: "fulfilled" PromiseResult: undefined
And this is not working. The block never gets removed.
By the way, I set
templateLock
to false.What I’m doing wrong?
Thanks.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘removeBlocks() action not working’ is closed to new replies.