K
K
kushnirukd2017-09-10 17:33:56
React
kushnirukd, 2017-09-10 17:33:56

Server-side Rendering React + Redux, how to pass parameters?

Hello. There was a question about the server rendering of the stack from REACT and REDUX.
Loading data like this:

/Component.jsx
...
static initialAction() { 
  return dispatch => { 
     axios.post('url')
     .then(res => res.data)
     .then(data=>dispatch({type: 'SET_TEST', test: data}))
     .catch(e=>console.log(e)); 
  }
}
...

On the server it looks like this:
/server.js
...
const promises = routes.reduce((acc, route) => { 
  if (matchPath(req.url, route) && route.component && route.component.initialAction){
     acc.push(Promise.resolve(store.dispatch(route.component.initialAction()))); 
  } 
  return acc; 
}, []);
Promise.all(promises).then(()=>{
//Вся морока с рендером
});
...

route.component.initialAction()- this is the function above
Everything works as it should, but let's say I need to render a dynamic page. How to pass parameter to this static function? Parameter from a line it is natural.
Parsing is an option req.url, but would that be the right solution?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question