Building a custom Gutenberg plugin this time is really challenging, you have to go with the fast-paced development and changes on the core plugin. Codes that you made worked perfectly are not guaranteed to stay that way, so you need to stay up-to-date and check their Github repo from time to time.

For instance, this one on the previous release : Is withAPIData being deprecated? withAPIData is a huge component to fetch custom endpoints and has been really useful, especially on post list blocks and on most blocks that are fetching database table data.

Reading on that issue and following In Gutenberg, now that withAPIData is being deprecated, how can I do an async call to a custom endpoint? at StackExchange here are two alternatives that you can use:

First is using withSelect which is what I’m currently doing. This code is from Matt Watson’s answer on StackExchange.

Then on your block Edit component. You can use this :

Another way is using wp.apiRequest component. You can use this inside your Edit component and to load custom API endpoints.

Depending on what you need, you can actually use both of them. I hope this could help on your plugin or theme development.

Leave a Reply

Your email address will not be published. Required fields are marked *