Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

perform asynchronous operations inside as a constant variable

$
0
0

I have one functional component

import { DEFAULT_LANGUAGE} from './translations';import React, { useState } from 'react';export const Welcome= () => {    const [appLanguage, setAppLanguage] = useState(DEFAULT_LANGUAGE);    console.log(appLanguage);};

translations.js

   import AsyncStorage from '@react-native-async-storage/async-storage';    export const DEFAULT_LANGUAGE= async () => {       try {           const response = await AsyncStorage.getItem('appLanguage');           if(response){               return response;           }           else{               return 'English';           }       }       catch (e) {           return 'English';       }    }

appLanguage returns promise object instead of value. How can I perform asynchronous operations inside as a constant variable?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>