Skip to content

Is there a better way to to make async API calls using the @wordpress/data module? #41537

Answered by adamziel
aberkow asked this question in Q&A
Discussion options

You must be logged in to vote

@aberkow You don't need a custom store if your code is running on today.uconn.edu domain – you can lean on the built-in @wordpress/core-data utilities. Here's a few resources you may find helpful:

I played with your code snippet and here's how the simplest version of these components could look like – note they don't rely on a custom store:

import { useEntityRecords } from '@wordpress/core-data';

const ArticleList = () => {
  const { records: selectedArticles } = useEntityRecords('postType', 'page');

  return (
    <>
      <h1>Latest Articles</h1>
      {
        selectedAr…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@aberkow
Comment options

Answer selected by aberkow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants