Implementing Socket.io with ReactJS ES6

前端 未结 3 1615
孤街浪徒
孤街浪徒 2021-01-30 14:39

I\'m having trouble incorporating SocketIO client into my project as I have me project set up isomorphically. After including the socket file in my base html, I try to call

3条回答
  •  暖寄归人
    2021-01-30 15:15

    I had the same weird problem with socket.io and React. I wanted to determine a clear line of dependency injection with props to other components from my main.jsx file. Turned out that I only had to initialize io like this...

    const socket = window.io();
    

    And that was it. It worked.

提交回复
热议问题