Replies: 2 comments
-
maybe @kalijonn ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can use dependent queries to conditionally query the api. However it doesn't work for atomWithSuspenseQuery yet. you can use atomWithQuery which has the enabled flag to conditionally query the api. import { unwrap } from 'jotai/utils'
const oidcAtom = atomWithQuery((get) => {
const homeResponse = get(unwrap(apiHomeDocumentAtom))
const oidcMetadataUrl = homeResponse?.data.homeDocument.getLink("oauth_server_metadata_uri")?.href
return {
queryKey: ['oidcMetadata', oidcMetadataUrl],
queryFn: async () => {
if (oidcMetadataUrl === undefined) {
throw new Error('No URL to get OpenID Connect metadata')
}
return await doFetch({ url: oidcMetadataUrl })
},
enabled: !! homeResponse,
}
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I'm wondering if anyone can help? I'm using Jotai with React Query, and that's all working great. However, I'm trying to build a UI that works against a fully hypermedia API, so some of the calls I need to make can only be determined based on the result of another call. And, of course, all of the calls are asynchronous.
Writing an
atomWithSuspenseQuery
that makes a single API call is easy. However, what I'm needing to do is resolve a value from oneatomWithSuspenseQuery
for use in another one, and I can't work out how to correctly do this.For example, in order to get the OpenID connect metadata, I need to:
atomWithSuspenseQuery
.atomWithSuspenseQuery
that the UI component actually cares about.Is there a good way to do this? The best I've been able to work out so far is to write an
atomFamily
that takes the URL as a parameter, and then call the two in succession from a custom hook. Which works, but feels a bit icky.Cheers
Beta Was this translation helpful? Give feedback.
All reactions