-
First off, what a great package. Thank you for Even after reading through #1240, I still don't see the way to compose queries properly. The approach in that discussion relies on function useCompositeData(): UseQueryResult<string> {
const { data: data1 } = useData1();
const { data: data2 } = useData2();
const enabled = !!(data1 && data2);
return useQuery('somekey', () => getCompositeData(data1, data2), { enabled });
}
function getCompositeData(data1: string, data2: string): string {
// Of course, this could be any sort of transformation - sync or async
return data1 + " " + data2
} The problem that I see with this approach is that it fails to deal with error states from the dependent queries. In other words, what happens is I fear I may be trying too hard. How have others dealt with this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
if the transformation is synchronous, I wouldn't do a query for it at all, but more something like:
if the transformation is expensive or referential identity is important, I'd stick a useMemo around it :)
if you don't have data1, you can't compute the result. In your version, the |
Beta Was this translation helpful? Give feedback.
if the transformation is synchronous, I wouldn't do a query for it at all, but more something like:
if the transformation is expensive or referential identity is important, I'd stick a useMemo around it :)
if you don't have data1, you can't compute the result. In your version, the
someKey
query would be inidle
status because it is not enabled. You would have to check that if it isidle
, you basically have no…