Data APIs

createAsync

Edit this page

An asynchronous primitive with a function that tracks similar to createMemo. createAsync expects a promise back that is then turned into a Signal. Reading it before it is ready causes Suspense/Transitions to trigger.

This is light wrapper over createResource which serves as a stand-in for a future primitive being brought to Solid core in 2.0. It is recommended that createAsync be used in favor of createResource specially when in a SolidStart app because createAsync works better in conjunction with the cache helper.

component.tsx
import { createAsync } from "solid/router";
import { Suspense } from "solid-js";
import { getUser } from "./api";
export function Component () => {
const user = createAsync(() => getUser(params.id));
return (
<Suspense fallback="loading user...">
<p>{user()}</p>
</Suspense>
);

Options

NameTypeDefaultDescription
namestringundefinedA name for the resource. This is used for debugging purposes.
deferStreambooleanfalseIf true, Solid will wait for the resource to resolve before flushing the stream.
initialValueanyundefinedThe initial value of the resource.
onHydratedfunctionundefinedA callback that is called when the resource is hydrated.
ssrLoadFrom"server" | "initial""server"The source of the initial value for SSR. If set to "initial", the resource will use the initialValue option instead of the value returned by the fetcher.
storagefunctioncreateSignalA function that returns a signal. This can be used to create a custom storage for the resource. This is still experimental
Report an issue with this page