Repository navigation
Whether the execution sequence of multiple createeffects is fixed? #2423
Replies: 1 comment
|
Yes—the relative order of those three independent effects is not guaranteed. In your playground, all three read The createEffect reference explicitly states that order among multiple effects is not guaranteed. An order observed on the first render, or on one button click, should not be relied on for later updates. If the three operations must run in that order, put them in one effect: createEffect(() => {
const value = count()
console.log(0, value)
console.log(1, value)
console.log(2, value)
})The statements within that callback then follow ordinary synchronous JavaScript ordering. If your real use case is instead “derive a value, then use it in an effect,” make the derivation a createMemo: import { createMemo } from 'solid-js'
const doubled = createMemo(() => count() * 2)
createEffect(() => {
console.log(doubled())
})Solid runs effects after pure computations in the update cycle. That gives you the data dependency without coordinating separate side effects by their observed scheduling order. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In the following example, if you click the button twice in a row, the three createEffect will be executed in different order. Is this a normal situation?
https://playground.solidjs.com/anonymous/defd3744-637b-442b-807e-aaebfbc39df3

All reactions