Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Default value not working on android emulator API 25 #6

@a1lu

Description

@a1lu

Hi,

I tried to get a missing key from the storage, but it did not return the default value but null.
I debugged your code and found the issue in the get function. AsyncStorage does not return an error here (API 25, in emulator) but null. So that the returned value is null, not the default Value.

async get(key, defaultValue = null) {
    let value = defaultValue;
    try {
      value = await AsyncStorage.getItem(`${this.__createKey(key)}`);
      // value is null here
      value = JSON.parse(value);
      // still null
    } catch (error) {
      value = defaultValue;
    }
   // still null
    return value;
}

To fix this you could add a null check

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions