react-native-json-file-storage
Simple JSON file storage compatible with React Native.
This library implements/borrows getItem, setItem, removeItem and clear
main methods from AsyncStorage's implementation.
The main difference from AsyncStorage's implementation is that
you can store any serializable value, not only strings.
Usage
import { RNJsonFileStorage } from 'react-native-json-file-storage'
const storage = new RNJsonFileStorage({
name: 'root'
})
const testStorage = async () => {
try {
await storage.setItem('key', { name: 'John Doe' })
const value = await storage.getItem('key') /** { name: 'John Doe' } */
await storage.removeItem('key')
// or
// await storage.clear()
} catch (error) {
// Handle errors:
// JSON.stringify error...
// JSON.parse error...
// Write/read file error...
}
}
testStorage()TODO
- <input disabled="" type="checkbox"> Allow users to opt-in cache file data in memory