React Query data can be undefined
Hello, any idea how could i make it so i know my data is not undefined when doing like this using react-query:
this works perfectly fine:
7 Replies
the problem is with .some() creating a closure.
If you changed it to
you'd likely find that it works.
you can
or you can set the initial data
TanStack | High Quality Open-Source Software for Web Developers
Headless, type-safe, powerful utilities for complex workflows like Data Management, Data Visualization, Charts, Tables, and UI Components.
(maybe its possible) you can pass a promise as prop (the inicial query data) and block it with use(Promise) to handle the data in a blocking way
Or you could just
console.log(queries.query1.data ?? {})
to take care of the undefined case, that should never happen anyway.in theory as well, you could use suspense boundaries to block the rendering before the null-ish case
TS doesn't understand suspense boundries though, and still complains 😆