Search code examples
wordpresswordpress-gutenberggutenberg-blocks

Get information and attributes from other gutenberg blocks


Is it possible to get information, such as the block attributes, from other blocks from within a registerBlockType call?

E.g. if I have a block with InnerBlocks as the content, is it possible to get attributes from the blocks inside that InnerBlocks, or vice versa?


Solution

  • Yes it is possible if you manages your own store inside Gutenberg which is actually a Redux store. @wordpress/data

    It is recommended to keep logic of your multiple blocks separately in their own attributes (that's why they are blocks). For re-usability purpose you can make React components which can be used inside different blocks, in this way attributes of your block can be passed to the props of React Component.