Skip to content

Difference between $derived() and $derived.by()? #12000

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

You must be logged in to vote

One takes a function, useful for utility functions that return a closure or for more complex logic that requires a { ... } block.
These are equivalent:

const a = $derived(x * 2);

const b = $derived.by(() => x * 2);
const c = $derived.by(() => {
  return x * 2;
});

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@brunnerh
Comment options

@brunnerh
Comment options

@7nik
Comment options

@frederikhors
Comment options

@7nik
Comment options

Answer selected by frederikhors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants