Pros and cons of query destructuring
Hey, I'm just wondering if there are any non-obvious pros/cons when considering object destructuring for queries (
const { data: myData } = useMyQuery()) vs naming the query and using it as is (const myQuery = useMyQuery()). We currently destructure everything, but it seems cumbersome when there are multiple queries in the same component because you have to remap every query prop to a different const - we end up having isQuery1Error, isQuery2Error etc.1 Reply
other-emerald•3y ago
Hi 👋
Type narrowing used to be a concern but this is no longer an issue as of TypeScript 4.6. Please see: https://tkdodo.eu/blog/react-query-and-type-script#type-narrowing.
You can rename in a destructuring assignment, or write a custom hook that does this for you