The createElement
idea is nice, but limited only to the children of Success and not components within those. My current approach is the usage of useQuery
. Here is an example where I also supplied useParams for convenience, so I just need to call the hook useTenant()
and know I have the right data.
import { useParams } from '@redwoodjs/router'
import type { FindTenantById } from 'web/types/graphql'
import { useQuery } from '@redwoodjs/web'
import { QUERY } from 'web/src/components/Tenant/TenantCell/TenantCell'
export const useTenant = () => {
const { tenant } = useParams()
const query = useQuery<FindTenantById>(QUERY, { variables: { id: tenant } })
return query.data?.tenant
}
Of course we could also do other things with useQuery, like listening if it succeeded.
I already asked how to integrate it into generators for cells: Hooks as addition to Cells - #5 by dennemark
(But currently I am having issues with typings in my mono repo, so I have to place the hook somewhere else)