Since (at least, from what I understood of it) it acts as a “bridge”, or some sort of staging area of the data, my (probably wrong) understanding is that if one performs a POST request on the client side, he/she does so through a reducer, which updates the Redux state.
No, I’d say that redux manages your state locally, period. That is its job. If we take thunk out of the equation, you would have to have some helper function (or whatever) that is going to have to do two things - perform the POST, etc. and dispatch and action to update the redux state (if needed). These are two separate actions. It can get complicated - when do you update data? What if it fails and needs to update a different part of state? What if other actions need to be dispatched?
That can get messy so things like thunk and saga were invented. With those, you can move that logic out of your component and just call a specific action that triggers your thunk or saga. A thunk does it with a callback function (if I remember correctly) and sagas use generator functions. But they both do similar things - they allow you to elegantly handle async situations and allow you to extract all of that logic to somewhere else. But in both cases, you are still going to have to tell it how to update redux state and how.
This is where I get confused the most: what happens when because of this state change in the Redux store, there is a mismatch between the data in the store and the data in the database?
If you don’t want that, then don’t do that. There are different flows.
- Make POST.
- Assume it will succeed and update local state with the same data.
- Deal with any errors as they come.
or
- Make POST.
- Wait for response from POST.
- Update local state with correct data if successful, or deal with the error.
Does the Redux action update the DB (by hitting the endpoint), which then in turn causes the DB to send back updated data to the store as a state…
No, unless you are dealing with a library that integrates these things (it sounds like you aren’t) then you are in charge of those. They are two separate actions and you choose how to deal with those.
Does the Redux action update the DB (by hitting the endpoint) …
Traditionally, redux should have nothing to do with your DB. The only job of redux is to manage your local state. Things like thunk and saga allow you to have other effects in your app, including making http requests and saving data from the response into your local state - but you still have to do that yourself.
…which then in turn causes the DB to send back updated data to the store as a state,
That can work, but it isn’t redux that would normally to that, but a thunk or saga. They can handle the async action and tell redux to handle the state update, either before of after the http request, depending on your needs.
…or what the client sees after the update is actually the Redux store
The client should only be seeing the redux store, not what is directly in the DB. They are two different things, the DB and the redux store. Your client doesn’t look at the DB itself. You make queries to the DB (through your server) and those get reflected in the client’s redux store.
…with a promise that it will also get updated into the database?
That is where error handling comes in. See the two ordered lists above. It just depends on how you want to handle it.