S
SolidJS9mo ago
Kevv

Derived signals with args?

Docs says that we can create derived signals with functions like this:
const double = () => 2 * count();
const double = () => 2 * count();
Is it okay to add args to it? I mean something like this:
const countBy = (factor: number) => factor * count();

// later
return (
<>
<p>{count()} time 3 is: {countBy(3)}</p>
<p>{count()} time 4 is: {countBy(4)}</p>
</>
);
const countBy = (factor: number) => factor * count();

// later
return (
<>
<p>{count()} time 3 is: {countBy(3)}</p>
<p>{count()} time 4 is: {countBy(4)}</p>
</>
);
I know I can just multiply count in the template, but this is just an example, the actual use case is more complex.
4 Replies
deluksic
deluksic9mo ago
Yes, that is perfectly fine
Kevv
KevvOP9mo ago
Thanks, I was asking just in case, maybe I was breaking some rule or using it the wrong way, you know, the fact you can do somethings not always means you should.
lxsmnsyc
lxsmnsyc9mo ago
the concept of derivation relies on function composition, there's no specific rule to be understood. The only thing that matters is the call stack.
bigmistqke
bigmistqke9mo ago
If u haven't seen it already: https://youtu.be/cELFZQAMdhQ?si=VTqxwjB1tu-UUqpU is a great introduction to solid's reactivity and helped me a lot in getting an intuition to how this composing of reactive functions and automatic managing of dependencies actually work.
SolidJS
YouTube
Intro to SolidJS reactivity (in 5 minutes)
An introduction video that walks you through Solid's reactivity in under 5 minutes.
Want results from more Discord servers?
Add your server