@softwaresamm/react-native-json-file-storage
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @softwaresamm/react-native-json-file-storage

Weekly Downloads

1

Version

0.2.2

License

MIT

Unpacked Size

57.3 kB

Total Files

29

Last publish

Collaborators

  • sammsas
  • andresfdaza
  • aeroxmotion