reconcile
Edit this pagereconcile creates a store modifier that reconciles existing state with a new value.
Import
import { reconcile } from "solid-js/store";Type
function reconcile<T extends U, U>( value: T, options?: { key?: string | null; merge?: boolean; }): (state: U) => T;Parameters
value
- Type:
T
New value to reconcile against the current state.
options
key
- Type:
string | null
Key used to match items during reconciliation.
merge
- Type:
boolean
Controls whether reconciliation pushes updates to the leaves instead of replacing non-matching branches.
Return value
- Type:
(state: U) => T
Store modifier function.
Behavior
reconcileis for reconciling an incoming snapshot against existing store state.- With the default
key, array items are matched by"id"where possible and otherwise fall back to positional or reference matching. - Non-wrappable values are replaced directly.
- When
mergeisfalse, reconciliation prefers replacing non-matching branches. Whenmergeistrue, it pushes updates deeper into the structure.
Examples
Basic usage
import { createStore, reconcile } from "solid-js/store";
const [state, setState] = createStore({ todos: [] });
setState("todos", reconcile([{ id: 1, title: "Write docs" }]));