Last active
October 1, 2020 12:06
-
-
Save tpjnorton/52865bf734b3a9ee83c5d552eb8c59c7 to your computer and use it in GitHub Desktop.
An example of using the useWebSocket hook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ChatView = () = { | |
const wsRef = useWebSocket( | |
'wss://example.com/chat', | |
null, | |
(message) => alert(message), | |
() => alert('error!') | |
); | |
return ( | |
<div> | |
<button onClick={() => wsRef.current?.send('Hello, World!")}>Click Me!</button> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment