Utility functions for computedKey and computedKeys to recalculate atom only on specific map keys change
Author: ggkguelensanCreated Sep 17, 2025Updated Jan 25, 2026
Is there any plan to add utility functions library with computedKey and computedKeys that allow creating an atom which is recomputed only when specific keys in a map store change?
import { computedKey, computedKeys } from 'nanostores/utils'
export const $profile = map({ name: 'Kazimir Malevich', email: '[email protected]' } as const)
// Only recalculates when 'name' changes
export const $profileName = computedKey($profile, 'name')
export const $profileNameLength = computedKey($profile, 'name', name => name.length)
// Only recalculates when 'name' or 'email' change
export const $profileSummary = computedKeys($profile, ['name', 'email'], ({ name, email }) => `${name} (${email})`)The example above is synthetic. In practice, such utilities are especially useful when you have a large map store, for example with a large list of items keyed by id, and you want to avoid unnecessary recalculations when unrelated ids change.
Is there an existing pattern or recommended way to achieve this behavior using current Nanostores APIs, which I may have missed?
Source: nanostores/nanostores