...

/

Redux-Thunk: A better way to fetch data

Redux-Thunk: A better way to fetch data

Fetching data is Redux apps can be streamlined by using redux-thunk. We are going to use redux-thunk to fetch weather data

The idea behind redux-thunk is that we return a function from an action that gets passed dispatch. This allows us to do asynchronous things (like data fetching) in our actions:

function someAction()
  // Notice how we return a function – this is what's called a "thunk"!
  return function thisIsAThunk(dispatch) {
    // Do something asynchronous in here
  }
}
...