📚
qwik-1.10.0以降でuseComputed$(async ...)がdeprecatedに
See the release note.
以下のような等価な表現があるので書き換えましょう。
type Defined<T> = T extends undefined ? never : T;
export const useAsyncComputedQrl = <T>(qrlFn: QRL<() => Promise<T>>) => {
const sig = useSignal<T>();
useTask$(({ track }) => {
const result = track(qrlFn);
if ('then' in result) {
result.then(
(val) => (sig.value = val),
(err) => {
console.error('async computed function threw!', err);
throw err;
}
);
} else {
sig.value = result;
}
});
return sig as Signal<Defined<T>>;
};
export const useAsyncComputed$ = implicit$FirstArg(useAsyncComputedQrl);
Discussion