0

I am trying to dispatch multiple redux actions in a sequence (or at once, doesn't really matter) using Promise API and it is not working:

Promise.all([
    store.dispatch(action1()),
    store.dispatch(action2()),
    store.dispatch(action3()),
    store.dispatch(action4())
]).then(() => {
    res.send(renderToString(<Provider store={store}><App /></Provider>));
});

I keep getting the following error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'map' of null

What am I doing wrong?

Gasim
  • 7,615
  • 14
  • 64
  • 131
  • From what I can tell, `store.dispatch()` is synchronous, so there's no point in using promises here. I'm not familiar with react, but based on the answers to [this](http://stackoverflow.com/questions/24776540/reactjs-fails-with-an-error-cannot-read-property-map-of-undefined) question and [this](http://stackoverflow.com/questions/24706267/cannot-read-property-map-of-undefined) one, it looks like your error might be coming from the render line. – JLRishe Jan 27 '17 at 14:34
  • My actions themselves return promises and I have a middleware that creates the proper actions. I fixed this temporarily. There is something wrong with my one of my reducers. – Gasim Jan 27 '17 at 14:46
  • You may want to look at using some middleware such as 'Redux Thunk' – curv Jan 27 '17 at 14:50
  • I would have used thunk or saga but I didn't know about them when I started this project. The client-side is already deployed and is ready for production. Adding another middleware is not an option at this point. So, I am going to try to find a solution that doesn't affect client side code in any way. – Gasim Jan 27 '17 at 14:54
  • @Gasim, The error is presumably coming from somewhere else. As you said, may be your reducers. Is this question still relevant? – yadhu Jan 28 '17 at 16:51

0 Answers0