Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Created June 27, 2019 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhowellsmead/07413da70cb2c917ddbe40a09988c8e6 to your computer and use it in GitHub Desktop.
Save markhowellsmead/07413da70cb2c917ddbe40a09988c8e6 to your computer and use it in GitHub Desktop.
Gutenberg: get authors via API and create a mapped HTML list of the results
// https://developer.wordpress.org/block-editor/packages/packages-core-data/#example
const { withSelect } = wp.data;
function renderAuthorList( { authors } ) {
return (
<ul>
{ authors.map( ( author ) => (
<li key={ author.id }>{ author.name }</li>
) ) }
</ul>
);
}
const MyAuthorsList = withSelect( ( select ) => ( {
authors: select( 'core' ).getAuthors(),
} ) )( renderAuthorList );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment