I have 2 files:
// index.js
export async function main(){
// Here is a set of functions with which
// I get an array with different data. these functions
// are also asynchronous, so you should use
// "wait"; and hence this function is also
// async. That array is the "resultado" variable.
return Promise.resolve(resultado.join("\n"));
}
// App.js
import React, { useState } from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
import Constants from 'expo-constants';
import { main } from './Backend/index';
export default function App() {
const [someVal, setSomeVal] = useState('');
(async () => {
const awaitedVal = await main()
setSomeVal(awaitedVal)
})();
return (
<View style={styles.container}>
<Text style={styles.paragraph}>
<a> {someVal} </a>
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
As it is, it doesn't work (because being the function asynchronous, it doesn't work like that). I have two different files. How do I do it?
UPDATED: Now, a new error appears.