S
SolidJS•4mo ago
mbork.pl

How to create a `resource` which accepts two signals but only refetches when the second one changes?

Here is my use-case: I have a form with some settings (let's say that their combined values are the first signal) and an "apply" button (which should trigger the actual refetch, so it increments an integer signal just to update it). Now the fetcher needs the first signal to know what data to fetch, but the actual fetching should be triggered when the second signal changes. Any ideas?
4 Replies
bigmistqke
bigmistqke•4mo ago
something like const [resource] = createResource(signal2, () => doFetch(signal1())) ?
mbork.pl
mbork.pl•4mo ago
and then doFetch is a function which returns the actual fetcher, do I get it right? ah, no sorry ha that is pretty clever, thanks! I'm playing around with it right now... wow, it really seems to work, and is way simpler than what we had before now I will only submit this solution for review to a teammate who will find a problem with it if there is one 😉 submitted, I'll let you know how it goes thanks again!
bigmistqke
bigmistqke•4mo ago
Ur welcome! Glad it worked out!
mbork.pl
mbork.pl•4mo ago
ok, she now accepted my PR, which means that everything should be fine – thanks again!
Want results from more Discord servers?
Add your server