如何在文本输入中调用异步函数?
getTxt = async () => {
filetxt = 'abc';
currentFileName = this.props.navigation.getParam("currentFileName");
console.log(currentFileName);
try {
filetxt = FileSystem.readAsStringAsync(`${FileSystem.documentDirectory}${currentFileName}.txt`, { encoding: FileSystem.EncodingTypes.UTF8 });
console.log(filetxt);
} catch (error) {
console.log(error);
}
return filetxt;
}
render() {
return (
<View style={{ flex: 1 }}>
<TextInput
multiline = {true}
style={{ margin : 10 }}
>{ await this.getTxt() }
</TextInput>
<Button onPress = { this.FunctionToOpenFirstActivity } title = 'Save'/>
</View>
);
}
有一个错误“等待是保留字”,知道吗?