Skip to content

Commit 79898cf

Browse files
docs: explain signal object and array updates (#1627)
docs: explain signal object updates Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 12dcb64 commit 79898cf

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ setCount((prevCount) => prevCount + 1);
7272
console.log(count()); // output: 1
7373
```
7474

75+
When a signal contains an object or array, mutating it directly does not notify subscribers because the setter was not called.
76+
Use the setter to create a new object or array instead:
77+
78+
```jsx
79+
const [items, setItems] = createSignal(["apple", "banana"]);
80+
81+
setItems((currentItems) => [...currentItems, "cherry"]);
82+
```
83+
84+
For state that requires frequent nested updates, consider using a [store](/concepts/stores) instead.
85+
7586
## Reactivity
7687

7788
Signals are reactive, which means that they automatically update when their value changes.

0 commit comments

Comments
 (0)