Sitelet https://github.com/unjs/unstorage/issues/752
Skip to content

Support React Native(Async Storage) #752

Description

@hairyf

Describe the feature

import { createAsyncStorage } from '@react-native-async-storage/async-storage'
import { defineDriver } from 'unstorage'

export const asyncStorageDriver = defineDriver<{ id: string }, never>((options) => {
  const storage = createAsyncStorage(options.id)
  return {
    name: 'async-storage',
    options,
    async hasItem(key) {
      return !!(await storage.getItem(key))
    },
    async getItem(key) {
      return storage.getItem(key)
    },
    async setItem(key, value) {
      return storage.setItem(key, value)
    },
    async removeItem(key) {
      return storage.removeItem(key)
    },
    async getKeys() {
      return storage.getAllKeys()
    },
    async clear() {
      return storage.clear()
    },
  }
})

Additional information

  • Would you be willing to help implement this feature?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions