-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
you can turn off automatic connection beforehand #204
Comments
There's a third parameter to the useWebSocket hook which isn't documented. Setting it to false will prevent automatic connection and disconnect the websocket if it is already connected |
This should've been documented. I've been using hours to find a workaround for this :D |
I only found out about it because I had a feature request to add it in: #208 |
I’m sorry for your time! It is not entirely undocumented: https://github.com/robtaussig/react-use-websocket#interface Do you have any thoughts regarding a better place for it? |
I was looking for a section that would show how to disable it at initialization. |
I stumbled upon my solution to my react-native problem in this thread. I want the websocket to disconnect when the app is in the background and reconnect when the app is foregrounded. Some delay could be built into this too. Here's how I solved it for my use case in react-native: import { useAppState } from "@react-native-community/hooks"
// in your functional component:
const appState = useAppState()
const appIsActive = appState === "active"
const ws = useWebSocket(
socketURL,
{
shouldReconnect: () => appIsActive,
// Other options
},
appIsActive, // boolean to indicate if the websocket should be connected or not.
) |
i want to cancel automatic connection beforehand how can i do it
The text was updated successfully, but these errors were encountered: