(First off, this doesn't work with the live site on github.io. Clone this repo to try this step out)
Redux Thunk middleware for actions with service calls. The documentation is here:
https://github.com/reduxjs/redux-thunk
Action creators are a natural place to put service calls. Redux thunk middleware passes in the dispatch()
and getState()
from the store into the action creators. This allows the action creator itself to dispatch different actions in between async side effects. Combined with the async / await syntax, coding service calls is a cinch!
Most of the time, in a single-page app, we apply optimistic UI updates. We can update the UI before the network call completes so the UI feels more responsive.
-
open up
exercise/src/service/index.ts
and study the signature of the functions to call the service such as theadd()
function -
open
exercise/src/actions/index.ts
and fill in the missing content insideactionsWithService
- note that the
complete
andclear
functions require you to write your own wrapper function
- open
exercise/src/index.tsx
and follow the instructions in the TODO comment to make the app prepopulate with data from the service.