1

I know Dispatching actions in redux is sync. When i dispatch action to redux from react component in line 1 can i be 100% sure that line 2 in my react component has the updated redux state? I'm setting game data by dispatching getGameDataSuccess(data) action. Can i be 100% sure that in the immediate next line the new props will flow down? Right now when i console.log(this.props.lostLetters.gameData), i see the new game data. But can i be 100% sure this will always be the case?

getLostLettersGame(this.props.gameCenter.selectedGame.gameId)
              .then((data) => {
                this.props.dispatch(LostLettersActions.getGameDataSuccess(data));
                console.log(this.props.lostLetters.gameData);
                this.generateGame();
              })
Karan Jariwala
  • 727
  • 6
  • 17
  • Possible duplicate of [Is store.dispatch in Redux synchronous or asynchronous](https://stackoverflow.com/questions/43276291/is-store-dispatch-in-redux-synchronous-or-asynchronous) – bennygenel Sep 06 '17 at 07:59
  • I know dispatching actions in redux is sync. I'm not sure whether the props flow down to react component in synchronous way. When i dispatch action to redux from react component in line 1 can i be 100% sure that line 2 in my react component has the updated redux state? it seems to work as shown above. I'm not sure it always will. – Karan Jariwala Sep 06 '17 at 08:15

1 Answers1

5

You cannot be 100% sure that the updated state is rendered right after the dispatch call. mapStatetoProps is called when the component is about to re-render, which depends on whether React batches the updates or not. By default, React batches updates from event handlers.

You can refer https://github.com/reactjs/react-redux/issues/291

Akash Verma
  • 344
  • 3
  • 12