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.

import { createAsync } from "@solidjs/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

name

Type: string

A name for the resource. This is used for debugging purposes.

deferStream

Type: boolean

Default: false

If true, Solid will wait for the resource to resolve before flushing the stream.

initialValue

The initial value of the resource.

onHydrated

Type: function

A callback that is called when the resource is hydrated.

ssrLoadFrom

Type: "server" | "initial"

Default: "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.

storage

Type: function

Default: createSignal

A 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