createRenderEffect
1 |
|
A render effect is a computation similar to a regular effect (as created by createEffect
), but differs in when Solid schedules the first execution of the effect function. While createEffect waits for the current rendering phase to be complete, createRenderEffect
immediately calls the function. 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. In particular, refs will not be set before the initial effect call. Indeed, Solid uses createRenderEffect
to implement the rendering phase itself, including setting of refs.
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
afterward (together with effects). In particular, all signal updates within a render effect are batched.
Here is an example of the behavior. (Compare with the example in createEffect
.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
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.
Arguments¶
Name | Type | Description |
---|---|---|
fn | (v: T) => T | The effect function to be called. |
value | T | The initial value to be passed to the effect function. |
{/* TODO: Add code playground example */}