0
私はAsyncStorageからlang varを得るために、この非同期コード関数を持っています。そして、私はこの機能を構造(?)メソッドのすべてのアプリページで呼びたいと思います。しかし、私はそれを呼び出そうとすると、コードが同期しているように見え、私のloadedLangは= {_45:0、_81:0、_65:null、_54:null}です。どのように正しい方法でそれを行うには?ありがとう。インポートからasync関数を呼び出す方法は?
main.js
import load from "./components/languageLoad"
constructor(props) {
super(props);
let loadedLang = load();
console.log("LOADED", loadedLang);
this.state = {
settings: 1,
deviceLocale: "EMPTY"
};
}
languageLoad.js
import React, { Component } from 'react';
import { AsyncStorage} from 'react-native';
import Lang from 'react-native-i18n'
export default load = async() => {
try {
const customLang = await AsyncStorage.getItem('customLang');
if (customLang !== null && customLang !== undefined && customLang !== "") {
deviceLocale = customLang;
}
} catch (error) {
deviceLocale = Lang.locale.split("-")[0] || "uk";
}
console.log("------------", deviceLocale, '-------------');
console.log("------------", Lang.t('aboutAppText') , '-------------');
Lang.locale = deviceLocale;
return Lang;
}