Skip to content

Document useEntityProp() hook #9

Open

Description

@helgatheviking

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.

Activity

  1. flexseth commented on Apr 3, 2024

    @flexseth
    Contributor

    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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions