You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`createComputed` creates a new computation that immediately runs the given function in a tracking scope, thus automatically tracking its dependencies, and automatically reruns the function whenever the dependencies changes.
13
-
The function gets called with an argument equal to the value returned from the function's last execution, or on the first call, equal to the optional second argument to `createComputed`.
12
+
`createComputed` creates a new computation that immediately runs the given function in a tracking scope, thus automatically tracking its dependencies, and automatically reruns the function whenever the dependencies changes.
13
+
The function gets called with an argument equal to the value returned from the function's last execution, or on the first call, equal to the optional second argument to `createComputed`.
14
14
Note that the return value of the function is not otherwise exposed; in particular, createComputed has no return value.
15
15
16
-
`createComputed` is the most immediate form of reactivity in Solid, and is most useful for building other reactive primitives.
17
-
For example, some other Solid primitives are built from `createComputed`.
18
-
However, it should be used with care, as `createComputed` can easily cause more unnecessary updates than other reactive primitives.
16
+
`createComputed` is the most immediate form of reactivity in Solid, and is most useful for building other reactive primitives.
17
+
For example, some other Solid primitives are built from `createComputed`.
18
+
However, it should be used with care, as `createComputed` can easily cause more unnecessary updates than other reactive primitives.
19
19
Before using it, consider the closely related primitives [`createMemo`](/reference/basic-reactivity/create-memo) and [`createRenderEffect`](/reference/secondary-primitives/create-render-effect).
20
20
21
-
Like `createMemo`, `createComputed` calls its function immediately on updates (unless you're in a [batch](/reference/reactive-utilities/batch), [effect](/reference/basic-reactivity/create-effect), or [transition](/reference/reactive-utilities/use-transition)).
22
-
However, while `createMemo` functions should be pure (not set any signals), `createComputed` functions can set signals.
23
-
Related, `createMemo` offers a readonly signal for the return value of the function, whereas to do the same with `createComputed` you would need to set a signal within the function.
21
+
Like `createMemo`, `createComputed` calls its function immediately on updates (unless you're in a [batch](/reference/reactive-utilities/batch), [effect](/reference/basic-reactivity/create-effect), or [transition](/reference/reactive-utilities/use-transition)).
22
+
However, while `createMemo` functions should be pure (not set any signals), `createComputed` functions can set signals.
23
+
Related, `createMemo` offers a readonly signal for the return value of the function, whereas to do the same with `createComputed` you would need to set a signal within the function.
24
24
If it is possible to use pure functions and `createMemo`, this is likely more efficient, as Solid optimizes the execution order of memo updates, whereas updating a signal within `createComputed` will immediately trigger reactive updates some of which may turn out to be unnecessary.
A render effect is a computation similar to a regular effect (as created by [`createEffect`](/reference/basic-reactivity/create-effect)), but differs in when Solid schedules the first execution of the effect function.
13
-
While `createEffect` waits for the current rendering phase to be complete, `createRenderEffect` immediately calls the function.
14
-
Thus the effect runs as DOM elements are being created and updated, but possibly before specific elements of interest have been created, and probably before those elements have been connected to the document.
15
-
In particular, **refs** will not be set before the initial effect call.
12
+
A render effect is a computation similar to a regular effect (as created by [`createEffect`](/reference/basic-reactivity/create-effect)), but differs in when Solid schedules the first execution of the effect function.
13
+
While `createEffect` waits for the current rendering phase to be complete, `createRenderEffect` immediately calls the function.
14
+
Thus the effect runs as DOM elements are being created and updated, but possibly before specific elements of interest have been created, and probably before those elements have been connected to the document.
15
+
In particular, **refs** will not be set before the initial effect call.
16
16
Indeed, Solid uses `createRenderEffect` to implement the rendering phase itself, including setting of **refs**.
17
17
18
-
Reactive updates to render effects are identical to effects: they queue up in response to a reactive change (e.g., a single signal update, or a batch of changes, or collective changes during an entire render phase) and run in a single [`batch`](/reference/reactive-utilities/batch) afterward (together with effects).
18
+
Reactive updates to render effects are identical to effects: they queue up in response to a reactive change (e.g., a single signal update, or a batch of changes, or collective changes during an entire render phase) and run in a single [`batch`](/reference/reactive-utilities/batch) afterward (together with effects).
19
19
In particular, all signal updates within a render effect are batched.
20
20
21
21
Here is an example of the behavior. (Compare with the example in [`createEffect`](/reference/basic-reactivity/create-effect).)
@@ -49,9 +49,16 @@ queueMicrotask(() => {
49
49
50
50
Just like `createEffect`, the effect function gets called with an argument equal to the value returned from the effect function's last execution, or on the first call, equal to the optional second argument of `createRenderEffect`.
Copy file name to clipboardExpand all lines: src/routes/solid-router/reference/data-apis/cache.mdx
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,14 +94,21 @@ The return value is a `CachedFunction`, a function that has the same signature a
94
94
This cached function stores the return value using the cache key.
95
95
Under most circumstances, this temporarily prevents the passed function from running with the same arguments, even if the created function is called repeatedly.
Copy file name to clipboardExpand all lines: src/routes/solid-router/reference/data-apis/query.mdx
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,14 +89,21 @@ The return value is a `CachedFunction`, a function that has the same signature a
89
89
This cached function stores the return value using the cache key.
90
90
Under most circumstances, this temporarily prevents the passed function from running with the same arguments, even if the created function is called repeatedly.
0 commit comments