diff --git a/docs/blocks/creating-dynamic-blocks.md b/docs/blocks/creating-dynamic-blocks.md index 28bd28f450ab61..e905d0b1a9a941 100644 --- a/docs/blocks/creating-dynamic-blocks.md +++ b/docs/blocks/creating-dynamic-blocks.md @@ -23,7 +23,12 @@ registerBlockType( 'my-plugin/latest-post', { posts: select( 'core' ).getEntityRecords( 'postType', 'post' ) }; } )( function( props ) { - if ( props.posts && props.posts.length === 0 ) { + + if ( ! props.posts ) { + return "Loading..."; + } + + if ( props.posts.length === 0 ) { return "No posts"; } var className = props.className; @@ -59,10 +64,16 @@ registerBlockType( 'my-plugin/latest-post', { posts: select( 'core' ).getEntityRecords( 'postType', 'post' ) }; } )( ( { posts, className } ) => { + + if ( ! posts ) { + return "Loading..."; + } + if ( posts && posts.length === 0 ) { return "No posts"; } - var post = posts[ 0 ]; + + let post = posts[ 0 ]; return { post.title.rendered }