SolidJSS
SolidJSโ€ข8mo agoโ€ข
12 replies
Gaba

how to use createAsync to feed createSignal

How should i guarantee that my signals are initialized AND fed with the Acessor from createAsync, while using <Suspense> ?
The documentation doesn't make clear how the Acessor created by createAsync interacts with createSignal. Will the createSignals correctly intereact with <Suspense>?

Which one of these two solutions would be the correct/recomended?

  const { id } = useParams<{id: string}>();
  const queryAcessor = createAsync(() => fetchSomething(id));
  const [value, setValue] = createSignal(queryAcessor()?.data?.value);

  return <Suspense fallback={<LoadingSpinner />}>
    {tileRadius()}
  </Suspense>

or
  const { id } = useParams<{id: string}>();
  const queryAcessor = createAsync(() => fetchSomething(id));
  const [value, setValue] = createSignal();

  createComputed(() => {
    const data = queryAcessor()?.data;
    if(!data) return

    setValue(data.value)
  })

  return <Suspense fallback={<LoadingSpinner />}>
    {tileRadius()}
  </Suspense>
Was this page helpful?