Skip to main content

Function: pickPreselected()

pickPreselected<T>(items, stored, keyOf): T | undefined

Defined in: composables/shared/utils/preselect.ts:12

Pick what a selectable list should start on.

Checkout must never render a payment method / carrier grid with nothing selected: the user should be able to hit Continue straight away. Prefer what the cart already stores; when it stores nothing — a fresh cart — or stores a value the backend no longer offers, fall back to the first option.

Kept separate from the components because both packages test pure logic in node and cannot mount an SFC / run an effect.

Type Parameters

T

T

Parameters

items

T[] | null | undefined

stored

string | null | undefined

keyOf

(item) => string

Returns

T | undefined