Search code examples
wordpresswordpress-gutenberg

Gutenberg: how to restrict the number of blocks inside InnerBlocks


const innerBlocksCount = innerBlocks.length;
  if (innerBlocksCount > allowedBlocksCount) {
    innerBlocks.slice(0, allowedBlocksCount);

    return (
      <InnerBlocks renderAppender={() => false} />
    );

I'm trying to make a clone for the column block in wordpresss,where the user will select either 1 or 2 or 3 blocks to put in, my block works fine but when the user put 3 blocks and then select 1, I want the last 2 blocks to be removed,

how can I achieve something like that as I have tried several things


Solution

  • you can identify the client Ids of the blocks required to be deleted and pass it as a parameter to removeBlocks function