Last active
February 15, 2020 20:08
-
-
Save markodayan/2e561a459a1b9df8443afee5f1f260d2 to your computer and use it in GitHub Desktop.
Asynchronous Code with redux-thunk (halting dispatch)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When we want to request information from a server, we do this within dispatching an action by asynchronously fetching | |
// data then dispatching to a reducer to alter app state. | |
// We achieve this with Redux middleware called 'redux-thunk' | |
// 'redux-thunk' allows you to call asynchronous tasks within action creators (dispatching actions). It halts the dispatch | |
// , performs the async request, then resumes the dispatch | |
// To use thunk it requires the 'applyMiddleware' method from 'redux' | |
// Thereafter it is applied to the store created as shown below: | |
const store = createStore(rootReducer, applyMiddleware(thunk)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment