O'Reilly logo

React Native By Example by Richard Kho

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a thunk

The Redux-Thunk library is a wrapper around your action creators, allowing them to perform asynchronous tasks before dispatching their intended action to the Redux store for a reducer to handle.

Here's how we will create a thunk: in the file where we create actions, we will export a function that returns a custom, asynchronous function within it, passing it the existing dispatch method. In this custom function, we will grab the results of a call to our getAsyncStorage method.

Then, within the same method, we will dispatch a private function, which we also create in the same file. That private function will return the action type, along with any parameters we wish to pass:

 // TasksRedux/app/actions/index.js import { getAsyncStorage ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required