Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import AsyncStorage from the correct package.
React Native
import [1] from '@react-native-async-storage/async-storage';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong import names like StorageAsync or AsyncStore.
✗ Incorrect
You must import AsyncStorage exactly from '@react-native-async-storage/async-storage' to use it.
2fill in blank
mediumComplete the code to save a value with AsyncStorage.
React Native
await AsyncStorage.[1]('username', 'john_doe');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using getItem instead of setItem to save data.
✗ Incorrect
Use setItem to save a key-value pair in AsyncStorage.
3fill in blank
hardFix the error in the code to retrieve a value from AsyncStorage.
React Native
const value = await AsyncStorage.[1]('username');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using setItem or removeItem instead of getItem to read data.
✗ Incorrect
Use getItem to retrieve a value by key from AsyncStorage.
4fill in blank
hardFill both blanks to remove a stored value and then clear all storage.
React Native
await AsyncStorage.[1]('username'); await AsyncStorage.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing clear with removeItem or using getItem to delete.
✗ Incorrect
removeItem deletes a specific key, and clear removes all keys from AsyncStorage.
5fill in blank
hardFill all three blanks to save, retrieve, and log a value using AsyncStorage.
React Native
await AsyncStorage.[1]('token', 'abc123'); const token = await AsyncStorage.[2]('token'); console.log([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Logging the wrong variable or mixing up setItem and getItem.
✗ Incorrect
First, setItem saves the token. Then, getItem retrieves it. Finally, logging the variable token shows the stored value.