Difference between $derived() and $derived.by()?
#12000
Answered
by
brunnerh
frederikhors
asked this question in
Q&A
-
|
Since in Svelte 5 docs are present two similar runes: let test = $derived(() => {});and let test = $derived.by(() => {}); |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Jun 11, 2024
Replies: 1 comment 6 replies
-
|
One takes a function, useful for utility functions that return a closure or for more complex logic that requires a const a = $derived(x * 2);
const b = $derived.by(() => x * 2);
const c = $derived.by(() => {
return x * 2;
}); |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
frederikhors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One takes a function, useful for utility functions that return a closure or for more complex logic that requires a
{ ... }block.These are equivalent: