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

Subscribing the store to changes

To update the listOfTasks key in AsyncStorage whenever a change is made to the state tree, we will call the subscribe method of our store. This creates a change listener to be called whenever an action has been dispatched and the state tree may have been changed.

It accepts a callback as its argument, and within that argument we can call the getState method of the store to access the state tree and retrieve any values we want from it.

Let's modify the index file found in the app folder so that it subscribes to changes to the store, firing a callback that calls saveAsyncStorage and passes it the most recent version of the listOfTasks array in our state tree:

 // TasksRedux/app/index.js ... import { saveAsyncStorage ...

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