Skip to content

useWebSocket failure #280

Description

@ManuelPrhyme

I get a react error that useWebSocket isnt a function when I call it in this code, passing in the server socket path and queryParams

import { useEffect } from "react"
import {useWebSocket} from 'react-use-websocket'
import throttle from 'lodash.throttle'

export function Home ({userName}){

    const WS_URL = 'ws://127.0.0.1:8000'
    const {sendJsonMessage} = useWebSocket(WS_URL,{
        queryParams : { userName}
    })

    // const socket = new WebSocket(`ws://localhost:8000?userName=${userName}`)

    // socket.addEventListener('open',() => {
    //     socket.send(JSON.stringify({x:23,y:223}))
    //     console.log("Connected to server")
    // }
    // )

    // socket.addEventListener('message',event => {
    //     console.log("The Server data is, ",JSON.parse(event.data))
    // })

    const sendJsonMessageThrottled = throttle(sendJsonMessage,50)

    useEffect(() => { 
        window.addEventListener('mousemove',(e)=>{
            sendJsonMessageThrottled({x:e.clientX, y:e.clientY})
        })
    },[])

    return <h1>Hello {userName}</h1>
}
Image

How can I resolve it

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions