WordPress / developer-plugins-handbook

Welcome to the WordPress Plugin Developer Handbook; are you ready to jump right in to the world of WordPress plugins?
https://developer.wordpress.org/plugins/
GNU General Public License v2.0
25 stars 16 forks source link

Document useEntityProp() hook #9

Open helgatheviking opened 7 months ago

helgatheviking commented 7 months ago

I came across this yesterday when building out a custom block and I found it used in one or two blog tutorials (example) but couldn't find it in the documentation.

flexseth commented 7 months ago

I came across this yesterday when building out a custom block and I found it used in one or two blog tutorials (example) but couldn't find it in the documentation.

I believe the documentation is not automatically populating, possibly because there isn't a JS DocBlock associated with the source code in Core. Not sure how this data is pulled into the Plugins Handbook...

Here's the code from the Block Editor source

https://github.com/WordPress/gutenberg/blob/80ff5e84793888f9891b66f737f7bb5d84818237/packages/editor/src/bindings/post-meta.js#L4

What does it do?

It looks like the useEntityProp hook is used contextually access post_meta from the @wordpress/core-data datastore. It's a fairly advanced JavaScript hook that can be a bit confusing to implement.

Where can I find an example use?

This may be a good candidate for the block-development-examples repo.

Or discussion can be had if adding comments in the documentation will auto-populate the info for the hook.

If you want to raise a question about an example for useEntityProp in the block-development-examples repo - that may be a good place for a simple example of what this hook does.

Or maybe it should be provided in the Plugins Handbook, unsure of the scope.

Here's a video that may go over the hook https://www.youtube.com/watch?v=MtVRifFbUaQ

Here's a repo that may cover it already... https://github.com/ryanwelcher/twitch/tree/65d1f9f5b7ea65b4388ea02a16c974752ad1872e/plugins/display-meta

Finished prototype from the video above https://blockdevelopercookbook.com/recipes/post-meta-testimonial-block/