Skip to content

SvelteSet infinite loop #14123

Closed Answered by brunnerh
megashrieks asked this question in Q&A
Discussion options

You must be logged in to vote

I suspect that this is expected, you read and write to a reactive object in the same $effect, causing it to trigger again.

Here would be a minimal example causing the same:

<script>
	$effect(() => {
		let v = $state(0);
		v = v + 1;
	})
</script>

Would recommend not unnecessarily creating stateful objects in the $effect and/or untracking the read operations.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by megashrieks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants