I have a $state
with an array:
let clicks = $state([])
I have an effect, which references the clicks
state:
$effect(() => {
// Box selection
if (autoDetectSettings.value.mode === 'box' && drawingBox && clicks.length === 2) {
const poly = objectSchema.parse({
id: createId(),
type: 'poly',
coords: [
{ x: clicks[0].x, y: clicks[0].y },
{ x: clicks[0].x, y: clicks[1].y },
{ x: clicks[1].x, y: clicks[1].y },
{ x: clicks[1].x, y: clicks[0].y },
],
color: '#ffffff',
opacity: 0.15,
stroke_color: '#ffffff',
stroke_opacity: 1,
stroke_width: 2,
blend_mode: 'normal',
})
artboard.objects.push(poly)
}
})
Adding an $inspect
shows that the value of clicks
is updating, but the effect is not triggering. Adding a console.log(clicks)
at the start of the effect fixes the issue. What am I doing wrong?