Let's say I have a state that looks like this:
enum PlayState {
Playing,
Paused,
Error
}
const initialState = {
playState: PlayState.Playing,
};
This holds the state of the currently selected audio player. Using a control panel, user can change the state of the player from playing to paused and vice versa. Audio player react component listens to state changes and calls the audio player SDK (which can take a few seconds, and can error out potentially).
Since this is like an async procedure, can somehow async thunk be applied in this case, or the request, success, failure pattern? How to correctly handle discrepency between the TRUE state of the audio player, and the intended (requested) state?
Yes, it can be done using thunk, also using redux-observable, saga, suspense, hooks, and other approaches.
Here is a nice article showing examples with thunk, saga, suspense, and hooks: https://www.freecodecamp.org/news/loading-data-in-react-redux-thunk-redux-saga-suspense-hooks-666b21da1569
I think once you get familiar with even one of the above your problem will be a breeze to solve. :)