getLocales() returns a promise rather than an array as specified in the types when using devlient client and react native debugger

Please provide the following:

  1. SDK Version: 47
  2. Platforms(Android/iOS/web/all): iOS
  3. React Native Debugger
  4. JSC (not Hermes)
  5. Using dev client on 8081

There appears to be some odd behaviour, just wondering if anyone else has experienced it when using the debugger on an real iOS device.

Basically I just call getLocales() and do a system out, normally I expect something like

[{"currencyCode": "CAD", "currencySymbol": "$", "decimalSeparator": ".", "digitGroupingSeparator": ",", "languageCode": "en", "languageTag": "en-CA", "measurementSystem": "metric", "regionCode":
 "CA", "textDirection": "ltr"}]

which happens normally.

However, when I hook it up to react native debugger I get

1. Promise {_x: 0, _y: 0, _z: null, _A: null}

  1. _A: null
  2. _x: 0
  3. _y: 1
  4. _z: [{…}]
  5. __proto__: Object

I have the same issue. If you find an explanation, would you please share it here as well?)

Ideally they should just make the the type correct which is to return a promise, but I think that would break a lot of code that this is presently using.

You can have something like this to do the promise resolution on dev mode

async function workaroundForDebugModeThatReturnsPromise(obj) {
  if (__DEV__)
    return Promise.resolve(obj)
  } else {
    return obj;
  }
}

Or simply make the value a promise and adjust the logic appropriately.

await Promise.resolve(Localization.getLocales())

FYI I just chose the later since I think it’s a better DX for now.

I have the same problem with AsyncStorage and SecureStore

import { Alert, StyleSheet, Text, View } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';

const saveData = async (key,value) => {
  try {
    const jsonValue = JSON.stringify(value)
    await AsyncStorage.setItem(key, jsonValue)
  } catch (e) {
    // saving error
  }
}

const getData = async (key) => {
  try {
    const jsonValue = await AsyncStorage.getItem(key)
    return jsonValue != null ? JSON.parse(jsonValue) : null;
  } catch(e) {
    // error reading value
  }
}

const App = () => {
const dataTest = '{"usuario":"informacion de prueba"}';
saveData('Info-User', dataTest);
const resultado = getData('Info-User');
console.warn(resultado);

  return (
    <View style={styles.container}>
      <Text>HOLA MUNDO! </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});


export default App;

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.