我是React-Native的新手,并尝试使用Pubnub和React-Native创建井字游戏。
我正在使用以下教程,该教程可以在
获得https://www.pubnub.com/blog/multiplayer-mobile-tic-tac-toe-react-native-ios-android-part-one/
按照教程中给出的说明,我已经完成。
该错误来自App.js文件。
这是App.js文件代码
import React, { Component } from 'react';
import PubNubReact from 'pubnub-react';
import {Platform,StyleSheet,View,Alert,Text,} from 'react-native';
import Game from './src/components/Game';
import Lobby from './src/components/Lobby';
import shortid from 'shortid';
import Spinner from 'react-native-spinkit';
import prompt from 'react-native-prompt-android';
export default class App extends Component {
constructor(props) {
super(props);
this.pubnub = new PubNubReact({
publishKey: "********************",
subscribeKey: "*******************"
});
this.state = {
username: '',
piece: '', // Creator of the room is 'X' and the opponent is 'O'
x_username: '', // Username for the room creator
o_username: '', // Username for the opponent
is_playing: false, // True when the opponent joins a room channel
is_waiting: false, // True when the room creator waits for an opponent
is_room_creator: false,
isDisabled: false // True when the 'Create' button is pressed
};
this.channel = null;
this.pubnub.init(this); // Initialize PubNub
}
我在 this.pubnub = new PubNubReact
时出错错误是TypeError:对象不是构造函数(正在评估'new _pubnubReact.default')
我使用的版本如下
“ pubnub”:“ ^ 4.28.4”,
“ pubnub反应”:“ ^ 2.0.0”,
“反应”:“ 16.13.1”,
“ react-native”:“ 0.63.2”,
请帮助我,谢谢。
答案 0 :(得分:0)
PubNub React库已彻底更改,因此不再兼容。要解决此问题,您需要安装pubnub-react
依赖项的较早版本。
$ npm install pubnub-react@1