react-native - 意外的令牌,在 React Native 中应为“=>”
问题描述
我是 React Native 的新手,所以不熟悉箭头函数的用法。我正在尝试使用此代码来获得 wifi 许可。
我的代码
import { PermissionsAndroid } from "react-native";
async componentDidMount() {
await this.askForUserPermission();
}
async askForUserPermission()
{
try{
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Wifi Networks",
message: "We need your permission to access wifi networks"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED){
console.log("Thank you for your permission! :)");
}
else{
console.log("You will not be able to retrieve wifi networks list");
}
}
catch (err)
{
console.warn(err);
}
}
请帮帮我。
解决方案
它期望 componentDidMount() 在类中。与此类似的东西会起作用。
class someComponent extends React.Component {
componentDidMount() {
return this.askForUserPermission();
}
async askForUserPermission() {
// Other code abbreviated.
}
};
export default someComponent;
推荐阅读
- java - 从 java 中的 .yml 文件中获取信息时遇到问题
- python - 当只有一些有逗号时,如何在 Pandas Dataframe 的 CSV 中消除行尾的逗号?
- java - Spring/Hibernate:与非所有者相关联
- r - 将 str_length 应用于数据帧的问题
- javascript - 更改 jQuery 工具提示的“div 类”
- python - 如何在 Mathplotlib 中绘制具有不同颜色标签的一组数据的图例
- c# - 使用 C# 和 .Net 5 创建 COM
- javascript - 谷歌表格 NORMDIST(x,平均值,标准偏差,累积 T/F)到 JavaScript
- html - 修复侧导航栏
- ionic-framework - 目标入口点“@ionic-native/media-capture”缺少依赖项:-@ionic-native/core