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

In short, use the useSelect() hook or the withSelect() HOC utility from @wordpress/data to create a subscription to selected value. Either will trigger a render whenever the selected value changes in state: import { useSelect } from ‘@wordpress/data’; edit() { const selectedBlock = useSelect( ( select ) => select( ‘core/block-editor’ ).getSelectedBlock() ); useEffect( () => … Read more

Basic use of useState

This works. I’m not sure why, but separating the Player component in other component I can update the component from the button callback. Just to explain the use of useState here: the videoId attribute is saved in the comment delimiter block when saving the post. That is something that has already been achieved, it is … Read more