- Why are operations in the AsyncStorage API asynchronous?
- So that you can perform lots of storage operations concurrently.
- To avoid interfering with the responsiveness of the UI.
- They're not asynchronous operations, they're just returning promises to be consistent with other storage APIs.
- Which AsyncStorage API would you use to look up several items at once?
- AsyncStorage.getAll()
- AsyncStorage.filter()
- A combination of AsyncStorage.getAllKeys() and AsyncStorage.multiGet().
- How do you get the connectivity status of the device in a React Native application?
- You call NetInfo.getConnectionInfo() and read the resulting connection type.
- You call NetInfo.getConnectionInfo() and if it returns true, you're connected. Otherwise, you're offline.
- There's a global reactNativeConnectionInfo object that you can read from at any point to determine the status of the connection.
- How do you respond to a change in connectivity status in a React Native application?
- There's no way to respond to connectivity status changes.
- You can listen to the connectionChange event by callingĀ NetInfo.addEventListener('connectionChange', ...).
- You can provide a callback function to the NetInfo.onChange() API.