Under The Hood
frontend solidjs SolidJS 1.x / 2.x

createResource: Async Data Coordination & <Suspense> Trapping

Last updated
Prerequisites:
SolidJS createSignal
Promises and Suspense
  • solidjs
  • createResource
  • suspense
  • async
  • fetching
  • signals

Read at your depth

The practical view

`createResource` is Solid's built-in primitive for handling asynchronous data fetching. `const [data, { mutate, refetch }] = createResource(sourceSignal, fetcherFn);`. `data()` returns the fetched value, `data.loading` indicates active requests, and `data.error` captures failures. When used inside a `<Suspense fallback={<Loading />}>` boundary, Solid automatically suspends the boundary until the resource resolves.

The same idea in other frameworks

react equivalent
React 19 `use(fetchPromise)` inside `<Suspense>`.

Legacy vs modern

Manual async/await Signal State vs createResource + Suspense

Manual fetch orchestration causes race conditions and loading state boilerplate; `createResource` binds directly to Suspense.

before → after
Manual Fetch in createEffect
createEffect(async () => { setLoading(true); setData(await fetch()); }); // ❌ Race conditions
createResource with Suspense
const [user] = createResource(userId, fetchUser); // ✅ NEW: Auto-cancels stale requests & binds to Suspense

Interview gotchas

Context

Interviewers test your knowledge of asynchronous concurrency control in reactive systems.

The mechanical answer

`createResource` maintains an internal monotonic sequence counter (request ID) for each fetch invocation. When the source signal updates (e.g. `userId` changes from 1 to 2), the sequence number increments. When an asynchronous fetch promise resolves, `createResource` checks if the resolved request ID matches the latest sequence counter. If an older request (user 1) resolves after a newer request (user 2), the older result is silently discarded.

Trap

Do not implement manual cancellation booleans inside custom fetchers; `createResource` handles stale response discarding automatically.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.