question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
robtaussigcommented, Jun 1, 2019

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.

1reaction
bafxyzcommented, Mar 5, 2020

Also supporting idea to return object instead of the array from the hook

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found