T
TanStack•16mo ago
genetic-orange

Cannot subscribe to values in Next.js app

I'm having some trouble setting up a form in Next.js. I've tried following the guide in the docs and looked through issues on GitHub for some help with types. It seems to be working fine until I try to subscribe to values. Here's the error:
TypeError: Cannot read properties of undefined (reading 'templateId')
TypeError: Cannot read properties of undefined (reading 'templateId')
And here's my best attempt at a reproduction: https://codesandbox.io/p/devbox/tanstack-form-repro-4g3j28
3 Replies
flat-fuchsia
flat-fuchsia•16mo ago
That seems like a problem in mergeForm works under the hood 🤔 Does it work if you add a field for templateId? <form.Field name="templateId">
genetic-orange
genetic-orangeOP•16mo ago
@Leonardo Thanks! That was an oversight on the name prop. But it didn't get it working, unfortunately. What does seem to work is changing the selector from (values) => values.templateId to (values) => values?.templateId
flat-fuchsia
flat-fuchsia•16mo ago
What I tried instead was showing a nice JSON.stringify(values) and I noticed all fields were missing 😄 All fields not having a mounted component, to be precise

Did you find this page helpful?