Next.js error: cannot read properties of undefined (reading 'lenght')

I get this error: cannot read properties of undefined (reading 'lenght'): https://pastebin.com/JDxdK0u5 With this code:
const InternalHome = observer(() => {
// ...
const { locale, query, replace } = useRouter();

const cityById =
typeof query.cityId === "string"
? useQuery(convexApi.getCity.findCityById, {
id: parseInt(query.cityId),
})
: undefined;
const InternalHome = observer(() => {
// ...
const { locale, query, replace } = useRouter();

const cityById =
typeof query.cityId === "string"
? useQuery(convexApi.getCity.findCityById, {
id: parseInt(query.cityId),
})
: undefined;
Pastebin
Call StackuseSelector.skipCheckjavascript\node_modules.pnpm@legen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No description
No description
No description
2 Replies
sshader
sshader•12mo ago
React doesn't allow hooks to be called conditionally (https://legacy.reactjs.org/docs/hooks-rules.html) You might wand something like useQuery(convexApi.getCity.findCityById, typeof query.cityId === "string" ? { id: parseInt(query.cityId) } : "skip") (See https://docs.convex.dev/client/react#skipping-queries)
Rules of Hooks – React
A JavaScript library for building user interfaces
Convex React | Convex Developer Hub
Convex React is the client library enabling your React application to interact
FleetAdmiralJakob 🗕 🗗 🗙
Top, thank you, this skip feature is awesome

Did you find this page helpful?