John Beasley
John Beasley

Reputation: 3075

ReactJS Chatkit is not defined

I made some progress on the tutorial found here:

https://www.youtube.com/watch?v=6vcIW0CO07k

But I got stuck around the 19 minute mark.

Basically, the tutorial is to build a Instant Messenger application using React and Chatkit.

I am receiving a "Failed to comile" message using the following code, which is a file named 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

The error message reads:

Failed to compile.

./src/ChatScreen.js
  Line 6: 'Chatkit' is not defined no-undef

Here is a link to my github repository. Why am I receiving this error?

https://github.com/rezzworks/REACT-SLACK-CLONE

Upvotes: 0

Views: 215

Answers (1)

Natsathorn
Natsathorn

Reputation: 1528

After I have a look in their documentation. I think you better import it this way.

import { TokenProvider } from "@pusher/chatkit-client-react"

I think the problem is version different. The VDO you watch is from last year, they might have some changed on their package.

FYI: https://pusher.com/docs/chatkit/getting_started/react#adding-a-token-provider-to-your-app

Upvotes: 1

Related Questions