javascript - ReactJS Chatkit 未定义
问题描述
我在此处找到的教程上取得了一些进展:
https://www.youtube.com/watch?v=6vcIW0CO07k
但我被困在 19 分钟左右。
基本上,本教程是使用 React 和 Chatkit 构建 Instant Messenger 应用程序。
我使用以下代码收到“无法编译”消息,该代码是一个名为 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
推荐阅读
- arrays - 从结构数组中查找最旧的日期(C 代码)
- c# - 尝试添加水印时,iText7 文档没有页面
- javascript - 我想在我的联系表格 7 下拉菜单中呈现图像值我正在使用 Wordpress
- sql - 如何使用 SQL 根据计数列取消分组记录
- android - 如何调整android渐变背景?
- azure - 无法通过 VPN 从本地专用 IP 网络访问 Azure Key Vault。IP 私有地址范围被禁止
- javascript - Javascript:同一顶级域上的浏览器选项卡之间的通信
- meshlab - 2020.12 Meshlabserver.exe在哪里
- c - Timing Quake III hack 仅在使用优化编译时有效
- python - 如何在 GridLayout 中拉伸 QSvgWidget