-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Document the useBlockWrapper hook in the block registration docs #26592
Conversation
Size Change: 0 B Total Size: 1.21 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for documenting useBlockProps
However, I'm wondering if we should include either as part of this or a new PR an example on how to implement for a block to support backward compatibility. Since useBlockProps
is only available in WP 5.6, any blocks using it will not work on WP 5.5 or older without coding around it.
Even now on the cusp of WP 5.6 release, 60% of sites are still running WP 5.4 or older.
https://wordpress.org/about/stats/
|
||
### attributes | ||
The first thing to notice here is the use of the `useBlockProps` React hook on the block wrapper element. In the example above, the block wrapper renders a "div" in the editor, but in order for the Gutenberg editor to know how to manipulate the block, add any extra classNames that are needed for the block... the block wrapper element should apply props retrieved from the `useBlockProps` react hook call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This phrasing feels a bit confusing to me but it could be a lack of technical knowledge. Specifically, this part: "but in order for the Gutenberg editor to know how to manipulate the block, add any extra classNames that are needed for the block...".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe going into details might create even more confusion :P
At this point in the learning curve of Gutenberg, people just need to know that this is important for Gutenberg to work well with their block. I'm not sure how I can express it better than that.
Related to #26100
This PR explains the use of useBlockWrapper hook for edit and save functions.
This PR along all the PRs attached to #26100 need to be merged right before WP 5.6