Skip to content

hamdikahloun/react-native-sync-storage-turbo-module

Repository files navigation

react-native-sync-storage-turbo-module

React Native Sync Storage: Turbo Native Module

Turbo Native Modules only work with the New Architecture enabled.

Features

  • Fully synchronous calls, no async/await, no Promises, no Bridge.
  • Faster than AsyncStorage
  • Uses JSI instead of the "old" Bridge
  • iOS and Android support

Installation

npm install react-native-sync-storage-turbo-module
yarn add react-native-sync-storage-turbo-module

Usage

import { setItem, getItem, getAllKeys } from 'react-native-sync-storage-turbo-module';

// ...

setItem('myKey', 'My Value');

const value = getItem('myKey');

const keys = getAllKeys()

removeItem('myKey')

clear()

redux-persist storage wrapper

If you want to use react-native-sync-storage-turbo-module with redux-persist, create the following storage object:

import { Storage } from 'redux-persist'
import { setItem, getItem, removeItem } from 'react-native-sync-storage-turbo-module';

export const reduxStorage: Storage = {
  setItem: (key, value) => {
    setItem(key, value)
    return Promise.resolve(true)
  },
  getItem: (key) => {
    const value = getItem(key)
    return Promise.resolve(value)
  },
  removeItem: (key) => {
    removeItem(key)
    return Promise.resolve()
  },
}

//...

const persistConfig = {
  //...
  storage: reduxStorage
}

const persistedReducer = persistReducer(persistConfig, rootReducer)

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT