To get the Gutenberg blocks data you can use one of a few approaches, depending on your needs.
Get all registered blocks
The Block package which contains methods to manage Gutenberg blocks is available under the
wp.blocks global object.
To get the data of all of the available Gutenberg blocks you’ll have to use the
getBlockTypes() method. It returns the array of objects, and it is available in the global scope inside the Gutenberg editor.
💡 NOTE: While the Blocks module is available as a global property inside the Gutenberg editor, you can install it independently via
npm for your project.
Get blocks added to the post
The Data module is used to manage the state of the Gutenberg editor and it is available via global
This will return the object of the store’s selectors.
Finally you can use the desired method to get the data, in our case the
💡 NOTE: If you don't have any elements added to the post, the
getBlocks() method will return an empty array.