Skip to content

[Content]: Document the lack of reactivity when mutating objects or arrays returned by createSignalย #1621

Description

@aradhakrishnan-INTL

๐Ÿ“š Subject area/topic

src/routes/(0)concepts/(2)signals.mdx

๐Ÿ“‹ Page(s) affected (or suggested, for new content)

/concepts/signals

๐Ÿ“‹ Description of content that is out-of-date or incorrect

If you create pass an array/object to createSignal, any changes to the underlying object won't be tracked by the reactivity system. Example:

const [arraySig, setArraySig] = createSignal([1, 2, 3]);
const copy = arraySig();
copy.push(...copy.slice(-3).map(x => x + 3));
console.log(arraySig()); /* `arraySig()` is now [1, 2, 3, 4, 5, 6], but UI won't update and effects won't rerun */

I believe this behaviour has to be documented.

๐Ÿ–ฅ๏ธ Reproduction in StackBlitz (if reporting incorrect content or code samples)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions