## Detect if a block has been deleted

Question

I’m currently working on a slider block for the block editor. While I use custom buttons to add a slide (which is a block), I can detect when a new block has been added to tell the slider script to refresh in order to take note of the newly created block (which acts as slide).

However, if I want to use the regular “delete block” action from the block’s toolbar menu, I cannot find out how to detect that.

I was already digging into the code and came to the conclusion that I had to detect when the action gets dispatched. However, I’m quite new to React and thus don’t know how to detect the removeBlock dispatch action.

I thought about subscribing to the store’s change but I cannot figure out which store to subscribe on:

const unsubscribe = subscribe( () => {
console.log( store.getState().lastAction ); // which store?
} );


Is this the correct way or is there something easier?

0
8 months 2021-12-30T08:33:47-05:00 0 Answers 0 views 0