Some values start from another value but can still be edited. A name badge defaults to the selected person's name, and the user may shorten it. When the person changes, the badge should reset to the new default.
Pass createSignal a function instead of a value, and the signal derives its value from that function:
const [badge, setBadge] = createSignal(() => names[person()]);Writing with setBadge overrides the value. When person changes, the function runs again and the override is replaced. No effect is needed to copy one signal into another.
Try it: the badge starts as "Ada Lovelace" and never follows the select. Make it derive from person(). Edit the badge, then pick another person: it should reset to that person's name.
Loading editor…