0

I want to convert these two strings into an object with key/value pair and being validated in zod:

{authors.allAuthors.map((author) => {
            return (
              <option key={author._id}>
                {author.firstName} {author.lastName}
              </option>
            );
          })}

And this is my schema entry for authors:

authors: z.string().transform((val) => JSON.parse(val))

My problem is that while doing so I'm receiving this error from the console:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')

What to do?

Marco Tidu
  • 11
  • 2
  • Could you share a few more details? My general experience with JS makes me think there's a separate issue causing the error you're seeing (looks like you're trying to read the length of an array that's actually `undefined` and since it's within a promise there's some context missing). Could you share the code where you're calling `parse` on your form data? – Souperman Oct 17 '22 at 01:16
  • Solved fetching just author._id from database :) – Marco Tidu Oct 17 '22 at 08:22

0 Answers0