reorder useWebSocket return values?
See original GitHub issue const [sendMessage, lastMessage, readyState] = useWebSocket(socketUrl);
I would assume first value reflects the state and the second one would be a callback
Examples:
const [state, setState] = useState(initialState);
...
const [state, dispatch] = useReducer(...);
That’s my gut feeling, but I’m not sure if it is a convention In this case, there are several states so it’s a bit unclear what the value should be
How about?:
const [{data, status}, sendMessage] = useWebSocket(socketUrl);
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top Results From Across the Web
WebSocket.send() and Socket.send() have no return value
In order to overcome this situation I would like to check if the Socket is free for new data or to check if...
Read more >Writing WebSocket client applications - Web APIs | MDN
In order to communicate using the WebSocket protocol, you need to create a WebSocket object; this will automatically attempt to open the ...
Read more >react-use-websocket
If the WebSocket is not shared (via options), then the return value is the underlying WebSocket, and thus methods such as close and...
Read more >React + WebSockets Project – Build a Real-Time Order ...
In this tutorial, we will see how to build an Order Book web ... getMaxTotalSum – this one returns the max value of...
Read more >WebSockets - A Conceptual Deep Dive
We cover what a WebSocket is, how WebSockets work, the challenges of ... the function return value as the value of the Sec-WebSocket-Accept ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a good suggestion, and in hindsight I probably should have done that from the get-go. For now, I worry about the implications of changing the order as it will break current usage. That said, I plan on bumping to v1 once I’ve had time to test this in a project I’m working on, and would be more comfortable introducing breaking changes in a major version bump.
I will leave the issue open, and if more people chime in with support, I might expedite the change.
Also supporting idea to return object instead of the array from the hook