Get selected block every time a new block is selected in Gutenberg


I want to get the selected block (an inner block) every time a new block is selected.

I am trying the following:

edit() {
  const selectedBlock = 'core/block-editor' ).getSelectedBlock();
  useEffect( () => {
    console.log( selectedBlock );
  }, [ selectedBlock ] );

The selected block is returned only when the block renders. Nothing happens when I select a new inner block. It works only when I click out of the parent block, then click again an inner block.

CyberJ 5 months 2022-07-19T17:15:59-05:00 0 Answers 0 views 0

Leave an answer