I had the same problem, and your solution was spot on. Thanks V. Sambor!
The flush: 'sync' option ensures that the subscription callback is called immediately when the state changes, rather than waiting for the next rendering cycle.
flush: 'sync'