Stores

createProjection

Creates a derived (projected) store. Like createMemo but for stores: the derive function receives a mutable draft and either mutates it in place (canonical) or returns a new value. Either way the result is reconciled against the previous draft by options.key (default "id"), so surviving items keep their proxy identity — only added/removed items are created/disposed.

Returns the projected store directly (no setter — reads only).

Use this when you want the structural-sharing / per-property tracking behaviour of a store on top of a derived computation. For simple read-only derivations, createMemo is lighter.


Import

import { createProjection } from "solid-js";

Type signature

function createProjection<T extends object = {}>(
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
seed: Partial<T>,
options?: ProjectionOptions
): Refreshable<Store<T>>;

Parameters

fn

Receives the current draft; mutate it in place or return new data. Return is convenient for filter/derive shapes where mutation is awkward.

seed

The backing store value to wrap and reconcile into

options

ProjectionOptionsname, key. key defaults to "id"; specify it only when your data uses a different identity field (e.g. { key: "uuid" } or { key: u => u.slug }).


Examples

// Mutation form — update individual fields on the draft.
const summary = createProjection<{ total: number; active: number }>(
(draft) => {
draft.total = users().length;
draft.active = users().filter((u) => u.active).length;
},
{ total: 0, active: 0 }
);
// Return form — produce a derived collection. Reconciled by `id` so each
// surviving user keeps the same store identity across recomputes.
const activeUsers = createProjection<User[]>(
() => allUsers().filter((u) => u.active),
[]
);

  • ://github.com/solidjs/x-reactivity#createprojection

ProjectionOptions

Options for derived/projected stores created with createStore(fn), createProjection, or createOptimisticStore(fn).

interface ProjectionOptions extends StoreOptions {
key?: string | ((item: NonNullable<any>) => any);
}

key

  • Type: string | ((item: NonNullable&lt;any&gt;) => any)

Key property name or function for reconciliation identity

ProjectionStoreReturn

Tuple returned by the derived createStore(fn, seed, options?) form.

type ProjectionStoreReturn<T> = [
get: Refreshable<Store<T>>,
set: StoreSetter<T>,
];

Refreshable

Brand applied to values that participate in the refresh() re-run protocol. Accessors receive this handle internally; projected stores expose it through their public return type so user-defined hooks that wrap createOptimisticStore / createProjection / projection-form createStore can have their return types inferred without leaking the internal $REFRESH symbol into public type signatures (TS4058).

type Refreshable<T> = T & { readonly [$REFRESH]: any };
Last updated: 7/4/26, 6:21 PMEdit this pageReport an issue with this page