Search code examples
react-nativedialogflow-es

React-Native: undefined is not an object (evaluating 'this.props = props')


I am new to react-native and i was trying to integrate dialogflow with react-native.

My code is:

import React, {Component} from 'react';
import { StyleSheet, View, Button } from 'react-native';
import { Dialogflow_V2 } from "react-native-dialogflow";

class App extends Component() {
  constructor(props) {
    super(props);

    Dialogflow_V2.setConfiguration(
        "sample.iam.gserviceaccount.com",
        '-----BEGIN PRIVATE KEY-----\sample\n-----END PRIVATE KEY-----\n"',
        Dialogflow_V2.LANG_ENGLISH,
        'sample-44ce3'
    );
  }
  render() {
    const { dialogflow } = this.props.Dialogflow_V2;
    return (
      <View style={styles.container}>
        <Button onPress={() => {
            dialogflow.requestQuery("hello", result=>console.log(result), error=>console.log(error));
          }}
        />
      </View>
    );
  }
}

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

export default App;

But it shows me this error

enter image description here

Can anyone explain me what problem is this exactly and what correction it needs? Thanks in advance.


Solution

  • That's because it cannot find Dialogflow_V2 reference from props.

    Delete this line inside of render function

    const { dialogflow } = this.props.Dialogflow_V2;
    

    use Dialogflow_V2 directly that you already have imported.

    Dialogflow_V2.requestQuery("hello", result=>console.log(result), error=>console.log(error));