Skip to content

Instantly share code, notes, and snippets.

@markodayan
Last active February 15, 2020 20:08
Show Gist options
  • Save markodayan/2e561a459a1b9df8443afee5f1f260d2 to your computer and use it in GitHub Desktop.
Save markodayan/2e561a459a1b9df8443afee5f1f260d2 to your computer and use it in GitHub Desktop.
Asynchronous Code with redux-thunk (halting dispatch)
// 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