Block editor: How to check if block editor has initialized and populated the data store?

Question

Within some JavaScript I have to get the current post content of Gutenberg. I am accessing this from jQuery (might be bad practice, however):

$(document).ready(function() {
           const { select } = wp.data;
           var currentPost = select("core/editor").getCurrentPost();
});

Within this construct the content of currentPost is undefined.

Within:

$(document).ready(function() {
        setTimeout(function(){
           const { select } = wp.data;
           var currentPost = select("core/editor").getCurrentPost();
        }, 3000);
});

currentPost is populated with everything I need.

As setTimeout is always a desperate solution I am asking you kindly for the correct callback/way to start a certain process as soon as Gutenberg is fully initialized?

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/block-editor-how-to-check-if-block-editor-has-initialized-and-populated-the-data-store/">

Block editor: How to check if block editor has initialized and populated the data store?</a>
0
, , Blackbam 3 months 0 Answers 30 views 0

Leave an answer