Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use another local storage instead of AsyncStorage #110

Open
flixyudh opened this issue Nov 1, 2022 · 1 comment
Open

Comments

@flixyudh
Copy link

flixyudh commented Nov 1, 2022

is it possible to use another local storage like RN MMKV-storage instead of AsyncStorage ?

I've tried something like this:

import Parse from 'parse/react-native';
import {MMKV} from './mmkv';

Parse.setAsyncStorage(MMKV); //here's i used MMKV instead of AsyncStorage
Parse.initialize('APP ID', 'JS ID');
Parse.serverURL = 'Server URL';

export const register = async (email, password) => {
  try {
    return await Parse.User.signUp(email, password);
  } catch (error) {
    alert(error);
  }
};

and an error appear

error XMLHttpRequest failed: "this.getAsyncStorage is not a function. (In 'this.getAsyncStorage()', 'this.getAsyncStorage' is undefined)"

dependencies:

"parse": "^3.5.0-beta.1",
"react-native-mmkv-storage": "^0.8.0",

but when i used
"parse": "^3.4.4",
there's no error and i think Parse class get stuck in

export const register = async (email, password) => {
  try {
    console.log('start') //appear
    return await Parse.User.signUp(email, password); //stuck here
    console.log('end') //never called
  } catch (error) {
    alert(error);
  }
};
@mtrezza mtrezza changed the title [Feature Request] - add ability to use another local storage instead of AsyncStorage Add ability to use another local storage instead of AsyncStorage Nov 1, 2022
@mortenmo
Copy link

mortenmo commented Jan 11, 2023

MMKV isn't async, I've set a new StorageController with MMKV this way:

const storage = new MMKV();
Parse.CoreManager.setStorageController({
    async: 0,

    getItem(path: string): string | null {
        return storage.getString(path) || null;
    },

    setItem(path: string, value: string) {
        storage.set(path, value);
    },

    removeItem(path: string) {
        storage.delete(path);
    },

    getAllKeys() {
        return storage.getAllKeys();
    },

    clear() {
        storage.clearAll();
    },
});

It would be great if that's an option within the library however, not just ASyncStorage

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

No branches or pull requests

3 participants