Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use Inner Blocks in a dynamic block? #7785

Closed
nyordanov opened this issue Jul 8, 2018 · 6 comments
Closed

Is it possible to use Inner Blocks in a dynamic block? #7785

nyordanov opened this issue Jul 8, 2018 · 6 comments
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@nyordanov
Copy link

How do I get the contents of InnerBlocks without using InnerBlocks.Content? Is there any event, which is fired when the inner blocks are modified?

@ajitbohra ajitbohra added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P labels Jul 8, 2018
@nyordanov nyordanov changed the title Is it possible to use Inner Blocks in a dynamic module? Is it possible to use Inner Blocks in a dynamic block? Jul 9, 2018
@jorgefilipecosta
Copy link
Member

Hi @nyordanov you can use the withSelect HOC https://wordpress.org/gutenberg/handbook/packages/packages-data/#withselect-mapselecttoprops-function-function to get a prop with all the inner blocks. The prop is updated each time the inner blocks are modified.
Something similar to:

edit: withSelect( ( select, ownProps ) => {
	return {
		innerBlocks: select( 'core/editor' ).getBlocks( ownProps.clientId )
	};
} ( edit component... );

If you need to be notified outside of a React component you can subscribe to the store https://wordpress.org/gutenberg/handbook/packages/packages-data/#subscribe-function.

I hope this answers your question and I'm closing this issue for now if you need additional information, feel free to reopen it.

@chrisvanpatten
Copy link
Contributor

@jorgefilipecosta any chance this will become available to server rendered blocks again? Would be great if blocks were rendered from the inside out, and the rendered markup was made available up the chain.

@noel-schenk
Copy link

yes please this is so important.
You could add an onChange event and pass the rendered data from the child block as a response to the onChange event like all the other compontens behave.

@noel-schenk
Copy link

noel-schenk commented Nov 19, 2018

@dadmor
Copy link

dadmor commented Aug 6, 2019

@jorgefilipecosta How can we render blocks that we get from withSelect HOC?

@jorgefilipecosta
Copy link
Member

If there is a need to get the content string of a block whose id was retrieved from withSelect I guess we can explicitly call wp.blocks.serialize and pass an array with that block. But I think that is something that should be avoided, maybe there is another way to solve the use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

6 participants