Answer the question
In order to leave comments, you need to log in
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));
}
}
...
/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 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 questionAsk a Question
731 491 924 answers to any question