export function RenderQuery< T extends QueryLike, G extends InferQueryLikeInput<T>, P extends InferQueryLikeData<T>,>({ useQuery, input, render,}: { useQuery: T; input: G; render: (data: P) => ReactElement;}) { const query = useQuery.useQuery(input); switch (query.status) { case "error": return <div>Sorry, something went wrong.</div> case "loading": return <LoadingSpinner />; case "success": return render(query.data); default: const _exhaustivenessCheck: never = query; return _exhaustivenessCheck; }}
<RenderQuery useQuery={trpc.user.details} input={{userId}} render={(data) => <div>{data.username}</div>} />