withAPIData Deprecated : Doing Async Call to Custom Endpoints on Gutenberg

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.
const { apiFetch } = wp;
const { registerStore, withSelect } = wp.data;
const actions = {
setUserRoles( userRoles ) {
return {
type: ‘SET_USER_ROLES’,
userRoles,
};
},
receiveUserRoles( path ) {
return {
type: ‘RECEIVE_USER_ROLES’,
path,
};
},
};
const store = registerStore( ‘phpbits/test-block’, {
reducer( state
Source: https://managewp.org/articles/17947/withapidata-deprecated-doing-async-call-to-custom-endpoints-on-gutenberg
source https://williechiu40.wordpress.com/2018/10/05/withapidata-deprecated-doing-async-call-to-custom-endpoints-on-gutenberg/