Next.js Discord

Discord Forum

Parse query parameter to number?

Answered
Southern rough shrimp posted this in #help-forum
Open in Discord
Avatar
Southern rough shrimpOP
Is there a way of only accepting query params of type number? i.e removing the manual parsing from string to integer?
Image
Answered by B33fb0n3
you can try catch the number. If it's not an number throw an error @Southern rough shrimp
View full answer

10 Replies

Avatar
Southern rough shrimpOP
in an ideal world, I could define the params as such (removing use of Number.parseInt
Image
Avatar
B33fb0n3
you can try catch the number. If it's not an number throw an error @Southern rough shrimp
Answer
Avatar
Southern rough shrimpOP
Yea but my idea is to not have to do that
cleaner code
Avatar
B33fb0n3
of course it would be a more cleaner code, but you also want to check the params. And the url is a string. In every case. So handle it as a string or try catch the number 🙂
Avatar
Southern rough shrimpOP
I may just change the id to string in the database so none of this number stuff is required
thanks for the help
Avatar
B33fb0n3
yea... please mark solution
Avatar
Southern rough shrimpOP
Image
Avatar
B33fb0n3
&752637460550385834 ?