From the course: Learning React Native

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using AsyncStorage

Using AsyncStorage

From the course: Learning React Native

Start my 1-month free trial

Using AsyncStorage

- [Instructor] Thus far, we've created a small app that allows us to add and visualize colors. It seems to be working just fine for us, but when we reload the application, we lose all the colors that we've added. So we need to save these colors in some sort of persistent storage. And that's exactly what AsyncStorage allows us to do. This means it allows us to save data locally on our phone. Let's go ahead and implement AsyncStorage. Now I'm in the hooks.js file because the values that I want to save are our colors. And we already have a useColors hook, that manages all of the functionality that has to do with colors. So, first, let's go ahead and import AsyncStorage from react-native. Next, we're going to need a function that we can use to load colors asynchronously, so we'll create an async function. We'll create a constant called colorData, this is where we will save any data that we load from AsyncStorage. We can…

Contents