robtaussig / react-use-websocket

React Hook for WebSocket communication
MIT License
1.63k stars 135 forks source link

React Native support #184

Open austingayler opened 1 year ago

austingayler commented 1 year ago

Hi, I didn't see anywhere in the docs whether or not this library is assumed to be compatible with React Native. It might be helpful for those choosing a websocket library for their project to say if there are any known incompatibilities, or if it's good to go.

This library: https://github.com/Sumit1993/react-native-use-websocket/issues/27

says it works, but I haven't tested.

WoonHaKim commented 1 year ago

When migrating to react 18(New RN architecture forces to use React 18), It seems like https://github.com/robtaussig/react-use-websocket/commit/b52c5f907526074ed19c83bac4e61a7422bf1969 can be RN not to work properly because of importing react-dom and using flushSync

michaelbachmann commented 1 year ago

Is it specific functionality that won’t work for version 4 in react native or will it just plain not work? Is it not advised to use this in a react native application?

I see there is a flag in the current code base for checking if we are in a react native environment to prevent EventSource feature in React Native. Which makes me think that ReactNative should be supported for useWebsocket?

https://github.com/robtaussig/react-use-websocket/blob/f8d9821a1343fb2904a4e3e102483a313433049d/src/lib/constants.ts#L35

hazmah0 commented 6 months ago

I tried using this library in a react-native app and it mostly works for my use case. The only issue I have is that I can't set headers for the http upgrade request that occurs before switching protocols. This is an issue in iOS at least where the user agent header is not set and therefore the request gets blocked in the WAF.

I forked this repository to solve it for now but would love to see that feature getting added in. Is there any plans to do so @robtaussig?

seba9999 commented 5 months ago

I was trying to add this lib to a RN project but I've face some strange behaviour when installing with the dependency tree ! The lib itself has react@">= 18.0.0 BUT react-dom (That I don't even want in my React Native app !) has react@"^18.3.1"

Then I can't add it to my expo project ( SDK 51 ) 😢

estmau commented 1 week ago

Any alternative or will we have to stay on 3.0.0?