AsyncStorage.

App.jsimport React, {useState} from 'react';
import {Text, View} from 'react-native';
export default function App(){
const [toDoList, updateToDoList] = useState([
{key: 1, title: "Monday", toDo: "shopping, cooking"},
{key: 2, title: "Tuesday", toDo: "business meeting"},
{key: 3, title: "Wednesday", toDo: "paying bills, visiting
family"}
])
let editHandler = () => {
...some code for updating item...
}
return(
<View>
{toDoList.map(item => {
return <Text key={item.key} onPress={editHandler}>
{item.title} : {item.toDo}
</Text>
})}
)}
import React, {useState, useEffect} from 'react';
useEffect(() => {getData()}, [])
let getData = async () =>  {
let keys = await AsyncStorage.getAllKeys()
if (keys.includes('storedToDoList')){
await AsyncStorage.getItem('storedToDoList')
.then(data => JSON.parse(data))
.then(data => {updateToDoList(data)
})
}
}
 useEffect(() => {
AsyncStorage.setItem("storedToDoList", JSON.stringify(toDoList))
}, [toDoList]
)
App.jsimport React, {useState, useEffect} from 'react';
import {Text, View} from 'react-native';
export default function App(){
const [toDoList, updateToDoList] = useState([
{key: 1, title: "Monday", toDo: "shopping, cooking"},
{key: 2, title: "Tuesday", toDo: "business meeting"},
{key: 3, title: "Wednesday", toDo: "paying bills, visiting
family"}
])
useEffect(() => {getData()}, [])
useEffect(() => {
AsyncStorage.setItem("storedToDoList", JSON.stringify(toDoList))
}, [toDoList]
)
let editHandler = () => {
...some code for updating item...
}
let getData = async () => {
let keys = await AsyncStorage.getAllKeys()
if (keys.includes('storedToDoList')){
await AsyncStorage.getItem('storedToDoList')
.then(data => JSON.parse(data))
.then(data => {updateToDoList(data)
})
}
}
return(
<View>
{toDoList.map(item => {
return <Text key={item.key} onPress={editHandler}>
{item.title} : {item.toDo}
</Text>
})}
</View>
)
}

--

--

--

Fullstack web developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Axios Lessons for VueJS Developers Ep. 5

Transforming payload with VTL in API Gateway — EventBridge integration

Brief introduction to Promises in Javascript

📊 billboard.js 2.0 is out! 🎉🎊

Vue VS React- Best Framework choice for 2022

How exactly does React handle events?

JavaScript Algorithm: Hex to Decimal

How to Use RxJS debounceTime with Angular

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yulia Y.

Yulia Y.

Fullstack web developer

More from Medium

Studio — Animatic

“Opportunities”

Face Mask Detector

Standing Out   By: Lumi C. & Tara P.