genuine_smiles
genuine_smiles
SSolidJS
Created by genuine_smiles on 12/23/2024 in #support
Trouble getting `createEffect` to work outside the browser
Could someone help me get this [1] example from the docs working in node, outside of the brower? I've tried a bunch of stuff, including wrapping it in createRoot() [2] without success. [1] https://docs.solidjs.com/reference/basic-reactivity/create-effect#:~:text=//%20assume%20this%20code,//%20goodbye
createRoot(() => {
const [count, setCount] = createSignal(0);

createEffect(() => console.log("count =", count()));
console.log("hello");
setCount(1);
setCount(2);

queueMicrotask(() => {
console.log("microtask");
setCount(3);
console.log("goodbye");
});
});

// --- overall output: ---
// hello
// microtask
// goodbye
createRoot(() => {
const [count, setCount] = createSignal(0);

createEffect(() => console.log("count =", count()));
console.log("hello");
setCount(1);
setCount(2);

queueMicrotask(() => {
console.log("microtask");
setCount(3);
console.log("goodbye");
});
});

// --- overall output: ---
// hello
// microtask
// goodbye
5 replies