问题
I am trying to integrate pubnub-react in react native. Here's my code:
import React, { Component } from 'react';
import PubNubReact from 'pubnub-react';
import {key1,key2} from '../config.js
export default class extends Component {
constructor(props) {
super(props);
this.pubnub = new PubNubReact({
publishKey: key1,
subscribeKey: key2
});
this.pubnub.init(this)
}
render() {
return null
}
}
This is throwing this error:
[[TypeError: Object is not a constructor (evaluating 'new _pubnubReact.default')]][1]
Version of react native is 0.62.1
回答1:
A PubNub engineer should be posting answer soon.
Alternative solution Posting this on Anshika Agrawal's behalf so that this post has an answer.
I solved the issue using pubnub instead of using pubnub-react. I referred to this link which resolved my issue – Anshika Agrawa
回答2:
I solved the issue using pubnub instead of using pubnub-react. I refered to this link https://www.pubnub.com/docs/nodejs-javascript/pubnub-javascript-sdk which resolved my issue
来源:https://stackoverflow.com/questions/61080350/object-is-not-a-constructor-in-react-native-when-using-pubnub-react