Consider the following code snippet
4 phương ánCó giải thíchDễ
using AsyncStorage in React Native. async function saveData(key, value) {
try {
await AsyncStorage.setItem(key, value);
}
catch (error) {
console.error('Error saving data', error);
}
}
async function readData(key) {
try {
const value = await AsyncStorage.getItem(key);
if (value !== null) {
console.log('Retrieved value:', value);
}
}
catch (error) {
console.error('Error reading data', error);
}
}What will be the output if saveData('username', 'john_doe') is called, followed by readData('username'), assuming no errors occur?
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi gọi hàm saveData('username', 'john_doe') và sau đó gọi hàm readData('username'), chúng ta sẽ thấy output là 'Retrieved value: john_doe'. Điều này là vì hàm saveData sẽ lưu trữ giá trị 'john_doe' vào AsyncStorage với key là 'username'. Sau đó, hàm readData sẽ đọc giá trị từ AsyncStorage và in ra console với giá trị vừa được lưu trữ. Nếu không có lỗi xảy ra, hàm readData sẽ trả về giá trị được lưu trữ, vì vậy output sẽ là 'Retrieved value: john_doe'.
Cùng chương 7
When using the Geolocation API, which of the following is not a prop of MapView?Có lời giảiCâu hỏiWhich method can be used for conditional rendering based on the platform?Có lời giảiCâu hỏiWhich module detects the platform on which the application operates?Có lời giảiCâu hỏiCả 17 câu của chủ đề17 câu