React Native TypeError: Cannot read property 'createClient' of undefined

Viewed 2348

I am new to React native framework. I have created app using 'create-react-native-app AwesomeProject'. I want to use BLE in my project so i installed the 'react-native-ble-plx' module but when i create the instance of BleManager it throws the error TypeError: Cannot read property 'createClient' of undefined. Why it throwing this error? My App.js is:

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"
}
});
2 Answers

add this.manager = new BleManager(); in componentDidMount()

Related