Component - AsyncStorage for key-value
This component shows how to save and load simple text data using AsyncStorage in React Native. It lets users type a value, save it, and then see the saved value displayed on the screen.
This component shows how to save and load simple text data using AsyncStorage in React Native. It lets users type a value, save it, and then see the saved value displayed on the screen.
View ├── TextInput ├── Button (Save) └── Text (Display saved value)
AsyncStorage in React Native?setItem, which returns a promise and requires await.save, store, and put do not exist in AsyncStorage API.import AsyncStorage from '@react-native-async-storage/async-storage';
async function test() {
await AsyncStorage.setItem('name', 'Alice');
const value = await AsyncStorage.getItem('name');
console.log(value);
}
test();import AsyncStorage from '@react-native-async-storage/async-storage';
function saveData() {
AsyncStorage.setItem('token', 'abc123');
console.log('Token saved');
}
saveData();removeItem, which returns a promise and should be awaited.getItem returns null, confirming deletion.Pass the test and this pattern moves unknown