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?

0
, , Blackbam 11 months 0 Answers 50 views 0

Leave an answer