createRenderEffect
createRenderEffect
provides a way to handle effects that need to run during rendering.
Usage
import { createSignal, createRenderEffect } from 'solid-js';
function Counter() { const [count, setCount] = createSignal(0);
createRenderEffect(count, (c) => { document.title = `Count: ${c}`; });
return <button onClick={() => setCount(c => c + 1)}>{count()}</button>;}
Similar to createEffect
, createRenderEffect
accepts two arguments:
- A reactive function to track dependencies of the side effect and return a value.
- A side effect function that will be called with the value returned from the reactive function.
There are some key differences between createRenderEffect
and createEffect
:
- Every
createRenderEffect
will run before anycreateEffect
runs. - If a
createRenderEffect
depends on an newly created async signal that is not resolved yet, it will trigger its parent<Suspense>
boundary. - If a
createRenderEffect
depends on an existing async signal that is not resolved yet, it will return with the previous value, similar tolatest
.
Last updated: 4/21/25, 10:01 AM
Edit this page on GitHub