React native and socket.io node not working

后端 未结 4 1153
一向
一向 2021-02-18 21:34

Below is my react native component and node server.js code that I am trying to connect to my node websocket backend.

My react code is running on the same computer as th

4条回答
  •  既然无缘
    2021-02-18 22:35

    I believe it should be

    const io = require('socket.io-client');
    

    Which does work for me.

    I remember running into these sorts of issues when using react native. A lot of socket.io tutorials (including the one on their page) assume you're using an older style of importing JS via script tags in an HTML doc. It looks like socket.io changed the namespace as I do remember it being socket.io-client/socket.io some time ago if memory serves...

提交回复
热议问题