-
Notifications
You must be signed in to change notification settings - Fork 11
Remote API
Melissa Stock edited this page Jul 4, 2019
·
1 revision
- An action informing the reducers that the request began.
- The reducers may handle this action by toggling an isFetching flag in the state. This way the UI knows it's time to show a spinner.
- An action informing the reducers that the request finished successfully.
- The reducers may handle this action by merging the new data into the state they manage and resetting isFetching. The UI would hide the spinner, and display the fetched data.
- An action informing the reducers that the request failed.
- The reducers may handle this action by resetting isFetching. Additionally, some reducers may want to store the error message so the UI can display it.
- Pay close attention to the shape of the state (how you're storing the information) before starting your implementations because async actions require a lot of state changes
- Redux Thunk makes it easy to dispatch actions that follow the lifecycle of a request to an external API.