Skip to content

Instantly share code, notes, and snippets.

@goiblas
Created April 4, 2020 14:35
Show Gist options
  • Save goiblas/03a8664317958366b74202915e10c3f0 to your computer and use it in GitHub Desktop.
Save goiblas/03a8664317958366b74202915e10c3f0 to your computer and use it in GitHub Desktop.
import { Spinner } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
const ArticlesList = ({ articles }) => {
if ( ! articles ) {
return (
<p style={{textAlign: "center", padding: "1rem"}}>
<Spinner />
</p>
);
}
return (
<ul>
{ articles.map( (article, index) => (
<li key={index}>
<a href={ article.link }>
{ article.title.rendered }
</a>
</li>
))
}
</ul>
);
}
export default withSelect( (select, props) => {
return {
articles : select( 'core' ).getEntityRecords( 'postType', props.type, { per_page: 6 } )
}}
)(ArticlesList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment