📚

qwik-1.10.0以降でuseComputed$(async ...)がdeprecatedに

2024/11/21に公開

See the release note.
https://github.com/QwikDev/qwik/releases/tag/%40builder.io%2Fqwik%401.10.0

以下のような等価な表現があるので書き換えましょう。

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