我在此处找到的教程上取得了一些进展:
https://www.youtube.com/watch?v=6vcIW0CO07k
但我在 19 分钟左右陷入了困境。
基本上,本教程是使用 React 和 Chatkit 构建即时通讯应用程序。
我使用以下代码收到“无法编译”消息,该代码是一个名为 Chatscreen.js 的文件:
import React from 'react'
import ChatKit from '@pusher/chatkit'
class ChatScreen extends React.Component {
componentDidMount () {
const chatManager = new Chatkit.ChatManager({
instanceLocator: 'v1:us1:5802c885-ab9d-409b-aa98-5dbcfc69efd1',
userId: this.props.currentUsername,
tokenProvider: new ChatKit.tokenProvider({
url: 'http://localhost:3001/authenticate'
})
})
chatManager
.connect()
.then(currentUser => console.log('currentUser', currentUser))
.catch(error => console.error(error))
}
render() {
return (
<div>
<h1>Chat</h1>
<p>Hello, {this.props.currentUsername}</p>
</div>
)
}
}
export default ChatScreen
错误消息如下:
Failed to compile.
./src/ChatScreen.js
Line 6: 'Chatkit' is not defined no-undef
这是我的 github 存储库的链接。为什么我会收到此错误?
最佳答案
在我查看了他们的文档之后。我认为你最好这样导入它。
import { TokenProvider } from "@pusher/chatkit-client-react"
我认为问题是版本不同。你看的VDO是去年的,他们的包装可能有一些变化。
仅供引用:https://pusher.com/docs/chatkit/getting_started/react#adding-a-token-provider-to-your-app
关于javascript - ReactJS Chatkit 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58108311/