How to build React apps on top of the WordPress REST API
Andrey Pokrovskiy
1.99K51

This is, by far, the best step-by-step REST API to React tutorial I’ve found so far. The first one I can follow and understand.

Just one doubt: I have a API call to get the menus (/wp-api-menus/v2/menus/2) instead of creating one dynamically trough the pages.

How would I implement that? I tried making an this.menuEndPoint, but it’s not working. Care to help me out?

// DataActions

constructor() {

this.menuEndPoint = `${appUrl}/wp-json/wp-api-menus/v2/menus/2`;

}

getMenu(cb) { // What is this cb?

this.api(this.menuEndPoint).then((response)=>{

this.getPages(response, cb)

});

// DataStore

this.exportPublicMethods({

getAllMenus: this.getAllMenus

..

getAllMenus() {

retur this.getState().data.menu;

// Nav

let allMenu = DataStore.getAllMenus(); <- This returns nothing.

Like what you read? Give Ricardo Nunes a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.