next-learn
next-learn copied to clipboard
Improving accessibility chapter changes validated fields to safeParse() but doesn't mention parsing them out
I'm on chapter 14 of the NextJS tutorial and midway through the page, it mentions changing the Zod parse() function to safeParse(). The code sample shows the line change from
const {customerId, amount, status} = CreateInvoice.parse({
to
const validatedFields = CreateInvoice.safeParse({
However, further down the line these variables are used as is in the amountInCents conversion as well as the SQL statements. This is counteracted in the complete code sample for the createInvoice() function by adding this on lines 17-18:
// Prepare data for insertion into the database
const { customerId, amount, status } = validatedFields.data;
This should be explicitly mentioned in the tutorial as well, to restore those variables from the validatedFields const that was just created.