I’m basically trying to implement this:
https://medium.freecodecamp.com/how-to-build-react-apps-on-top-of-the-wordpress-rest-api-bcc632808025

except with this starter kit:
https://github.com/davezuko/react-redux-starter-kit

The trouble that I’m running into is two fold.
1. I need to get data from the wordpress instance into my redux store as soon as I instantiate the store. I try to solve this problem by dispatching an asynchronous action right after I create my store in /store/createStore.js but it isn’t fast enough.

const store = createStore(
    makeRootReducer(),
    initialState,
    composeEnhancers(
      applyMiddleware(...middleware),
      ...enhancers
    )
  )
  store.dispatch( fetchEditorials() )
  console.log(store.getState())
  console.log('lets see')

store.getState() is not displaying the updated data.

  1. I need to generate routes using the slugs I get from the wordpress array. Before I can generate routes I need to make sure that the wordpress data is inside the store, but also I don’t know where to write this code.

Either here:

export const createRoutes = (store) => ({
  path        : '/',
  component   : CoreLayout,
  indexRoute  : Home,
  childRoutes : [
    CounterRoute(store),
    MovieRoute(store)
  ]
})

or I created a new function:

function buildRoutes (store) {
  return store.getState().editorial.data.map((posts, i) => {
    return (
      <Route component='' key={posts.id} path={`/$posts.slug`} />
    )
  })
}

then I would pass this into childRoutes from the code above.

Read more here: Implement Dynamic Routes Using React Redux Starter Kit


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: