Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@azuredivay Don't insult my Kotlin please 😉 That's JS (or possibly TS) react code.
-
b2plane63891y@cb219 i put question mark `?` and it wasn't supposed to be put because the `query` attribute adds it automatically. as if i was supposed to know that
-
@b2plane
You went with socket.Io. Deal with cancer. (Or better, learn real sockets. Or, as this seems web, real websockets.)
A quick glimpse at the URL spec would have told you that the "?" Is a separator and not part of the query string.
You explicitly mentioned java. -
I hope you have a really good reason to assign event handlers to a stateful networking primitive inside a UI component.
-
b2plane63891y@azuredivay got too lazy to write a detailed caption, i meant the backend (built in java) threw exception because of this frontend (built in react) code
-
So the frontend called the server with an url including TWO questionMarks and that caused a server error?
Feels like if the server request handler was set up nicely this would result in a "bad request" error or something like that indicating the url was malformed -
Concatting strings into a URL is a common source of mistakes
In plain JS it's made slightly less prone to mistakes if you'd use the native URL object with its searchParams attribute to do something like
const url = new URL(baseUrl); url.searchParams.add("username", username); url.searchParams.add("room-id", roomId);
To get the full adress you'd use
url.toString();
Allthough I'm not entirely happy with the URL or URLSearchParams objects as I would've liked to be able to use them as a one liner with an array Input. Using an append-fn for every param makes it too wordy. and if you don't you still have to remeber to put the & between params -
b2plane63891y@lorentz
1. I took this code from someone elses github
2. Im not a react expert so i have no idea how useEffect works under the hood
3. This code works fine
Spent 3 hours trying to debug why java threw null exception when user disconnects or connects to room id to chat. Guess where the fucking bug was
rant