Difference between useEntityProp and getEditedPostAttribute
-
When developing a custom sidebar for the block editor, a panel in the InspectorControls or a block, there are multiple ways to get the properties/fields for the post:
1. getEditedPostAttribute
According to its doc block it “Returns a single attribute of the post being edited, preferring the unsaved edit if one exists, but falling back to the attribute for the last known saved state of the post.”
When using it likegetEditedPostAttribute("meta")
it will get the whole meta, but it’s possible to also get other properties. Eg the featured image selector in the sidebar gets the attributefeatured_media
.2. useEntityProp
According to its doc block it “Hook that returns the value and a setter for the specified property of the nearest provided entity of the specified type.”
In the metabox to block guide it’s recommended to be used to get the meta like `useEntityProp(“postType”, postType, “meta”)”I understand, that the second one is a react hook and the first one would have to be used in a
useSelect
select mapper.But still, what exactly is the difference between these methods?
What is the preferred way and are there cases in which they don’t return the same data? As far as I can see, both return the current (maybe unsaved) state of the object.
- The topic ‘Difference between useEntityProp and getEditedPostAttribute’ is closed to new replies.