Skip to content

Commit e132394

Browse files
committed
add information about createEffect at top level, eagerly accessing signals in batch, and reference to batch from create-effect
1 parent 4981914 commit e132394

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/routes/reference/basic-reactivity/create-effect.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ createEffect((prevA) => {
4040
// ^ the initial value of the effect is 0
4141
```
4242

43-
Effects are meant primarily for side effects that read but don't write to the reactive system: it's best to avoid setting signals in effects, which without care can cause additional rendering or even infinite effect loops. Instead, prefer using [createMemo](/reference/basic-reactivity/create-memo) to compute new values that depend on other reactive values, so the reactive system knows what depends on what, and can optimize accordingly.
43+
Effects are meant primarily for side effects that read but don't write to the reactive system: it's best to avoid setting signals in effects, which without care can cause additional rendering or even infinite effect loops.
44+
Instead, prefer using [createMemo](/reference/basic-reactivity/create-memo) to compute new values that depend on other reactive values, so the reactive system knows what depends on what, and can optimize accordingly.
45+
However, if signals are set in an effect, computations subscribed to that signal will be executed only once the effect completes (see [batch](/reference/reactive-utilities/batch) for more detail).
4446

4547
The first execution of the effect function is not immediate; it's scheduled to run after the current rendering phase (e.g., after calling the function passed to [render](/reference/rendering/render), [createRoot](/reference/reactive-utilities/create-root), or [runWithOwner](/reference/reactive-utilities/run-with-owner)).
4648
If you want to wait for the first execution to occur, use [queueMicrotask](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) (which runs before the browser renders the DOM) or `await Promise.resolve()` or `setTimeout(..., 0)` (which runs after browser rendering).

src/routes/reference/reactive-utilities/batch.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ function batch<T>(fn: () => T): T;
88

99
This is a low level API that is used by Solid to batch updates.
1010
It holds executing downstream computations within the block until the end to prevent unnecessary recalculation.
11-
Solid Store's set method, Mutable Store's array methods, and Effects automatically wrap their code in a batch.
12-
This is useful for when you want to batch a set of computations that are not wrapped in a batch already.
11+
Although the computations listening for changes to the signal are not yet notified, accessing the value of a signal set within the batch will still return the updated value (in Solid versions >=1.4).
12+
13+
Solid Store's set method, Mutable Store's array methods, and Effects (unless it is defined outside a root) automatically wrap their code in a batch.
14+
This is useful in user-land for when you want to batch a set of computations that are not wrapped in a batch already.

0 commit comments

Comments
 (0)