WordPress / gutenberg-examples

Examples for extending WordPress/Gutenberg with blocks.
1.2k stars 316 forks source link

When use editEntityRecord for content it doesn't render automatically. #249

Open mijan-xs opened 1 year ago

mijan-xs commented 1 year ago
 const handlePageImport = async (page) => {
    const { getCurrentPostId, getCurrentPostType, getEditedPostContent } = select('core/editor');
    const { getEntityRecord } = select('core');
    const { editEntityRecord, saveEditedEntityRecord } = dispatch('core');
    const postId = getCurrentPostId();
    const postType = getCurrentPostType();
    const content = getEditedPostContent();
    const post = getEntityRecord('postType', postType, postId);
    await editEntityRecord('postType', postType, postId, {
        content: content + page.content,
    });
    await saveEditedEntityRecord('postType', postType, postId);
}

I used this code to import my demo from a custom post type. It imports my demo content to the page but doesn't render until I reload the page manually. After manually reloading I can see my demo content. but if I updated only the title then it's rendered automatically but only when I update the post manually.