String into ID !
That feels so simple and yet I can't manage to nail it on my code :/ Can anybody help? I have this ticketId value in a string and I just need to pass it as an argument in the correct format! What should I do?
15 Replies
Welcome! So
onEventIdChange
calls setEventId
with a plain string, not an id type? Is it coming from outside of Convex?Thanks! Yes, I'm fetching it with a QR reader
Ah okay. You could set the type of the useState to an id, and when you call
setEventId
, cast the string to an id with as
Simpler ^^
Passing 'skip'
when ticketId is falsy keeps the query from runningawesome, let me try that
I did fixed the error with the type, but now the ticket returning null, before it wasn't.
actly, it's not waiting for the qr code input with the ticket ID and going straight to null.. I'll sort that out! Thank you so much for the help!
Also linking https://docs.convex.dev/database/document-ids#serializing-ids
Another approach here when dealing with IDs coming from external sources is to have your function take in a
v.string()
instead of a v.id()
and use db.normalizeId
+ db.get
to check it's a valid ID (potentially throwing a specific error if not).Document IDs | Convex Developer Hub
Create complex, relational data models using IDs.
Pointing this out just in case --
useQuery
returns undefined
when it's loading or skipped (and might also return null
if you return null
or undefined
from your function), and if (!ticket)
would catch both of these, vs. something like if (ticket === undefined) { return "Loading..." } else if (ticket === null) { return null }
this is still in the same error I believe... On npm run dev the build is fully working, but getting this error when trying to deploy with Vercel.. I believe it's the same Id issue.. any thoughts?
What line of code does the type error reference
I can't manage to find it ;/ it says it's in that page but I don't see this event: ...
I think it might be referencing to this event, but it's weird that everything is working well on dev, but not on vercel deploy
Nevermind, just found the issue! Really glad for all the help!
No problem! Can you share the solution in case anyone else ends up here in the future?
Sure, it wasn't anything related to Convex tho. I just removed the full event argument in the validate function. I'll paste the code tomorrow.
Ah okay, no bigs then