gpt4 book ai didi

javascript - react native 类型错误 : Cannot read property 'createClient' of undefined

转载 作者:行者123 更新时间:2023-11-29 16:01:40 24 4
gpt4 key购买 nike

我是 React 原生框架的新手。我使用“create-react-native-app AwesomeProject”创建了应用程序。我想在我的项目中使用 BLE,所以我安装了“react-native-ble-plx”模块,但是当我创建 BleManager 的实例时,它抛出错误类型错误:无法读取未定义的属性“createClient”。为什么会抛出这个错误?我的 App.js 是:

import React from "react";
import { StyleSheet, Button, Text, View, Alert } from "react-native";
import { BleManager } from 'react-native-ble-plx';
export default class App extends React.Component {

constructor() {
super();
this.manager = new BleManager();
}

TestFunction() {
Alert.alert('Button Pressed !!!')
}

render() {
return (
<View style={styles.container}>
<Button onPress={ this.TestFunction } title="Learn
More"color="#841584" />
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
}
});

最佳答案

在componentDidMount()中添加this.manager = new BleManager();

关于javascript - react native 类型错误 : Cannot read property 'createClient' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52294985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com