0.2.2 • Published 3 years ago

@softwaresamm/react-native-json-file-storage v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

  • Allow users to opt-in cache file data in memory
0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago