block editor - What is the difference between useSelect and useEntityProp?

admin2025-01-08  3

I think I understand useSelect, (basically). For example:

 const slug = useSelect(
        ( select ) => select( 'core/editor' ).getEditedPostSlug()
    );

Will get the slug and set up a subscriber to the store so that if the value is changed slug will update and the the component will re-render?

But, I also have this:

const [ meta, setMeta ] = useEntityProp( 'postType', 'kea_activity', 'meta' ); 

This gets me the meta data from the store and a setter. Good.

If I use the setter to update the meta data it seems my component rerenders. I says seems because I am assuming that this is what is causing the rerender. I am pretty sure it is this. So - this implies that something is listening for updates to the meta data and rerendering when this changes. What is this "something"?

Thank you.

I think I understand useSelect, (basically). For example:

 const slug = useSelect(
        ( select ) => select( 'core/editor' ).getEditedPostSlug()
    );

Will get the slug and set up a subscriber to the store so that if the value is changed slug will update and the the component will re-render?

But, I also have this:

const [ meta, setMeta ] = useEntityProp( 'postType', 'kea_activity', 'meta' ); 

This gets me the meta data from the store and a setter. Good.

If I use the setter to update the meta data it seems my component rerenders. I says seems because I am assuming that this is what is causing the rerender. I am pretty sure it is this. So - this implies that something is listening for updates to the meta data and rerendering when this changes. What is this "something"?

Thank you.

Share Improve this question asked Nov 22, 2024 at 13:16 Justin WylllieJustin Wylllie 374 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Will get the slug and set up a subscriber to the store so that if the value is changed slug will update and the the component will re-render?

That is correct

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736267708a1216.html

最新回复(0)