Resource refetch doesn't trigger effect
I have this effect in my root layout (solid-start)
useUser:
When I call that
refetch
function from another component, I'd expect the effect in the 1st snippet to get re-run. Am I doing anything wrong?11 Replies
any console messages?
You're only calling useUser once, right? (otherwise, you have two different resources, one from each call)
If you want to call it twice, you could use my resource package to cache the request: https://primitives.solidjs.community/package/resource#makecache
Solid Primitives
A library of high-quality primitives that extend SolidJS reactivity
Oh wow, no, I'm calling it twice 🤦
Thank you so much
That's like a mini react-query, no?
That's awesome
Thank you :D
I hope it helps you. Yes, it's like the Lego bricks mini version of some of TanStack query's features.
I find that I rarely need the full power of TanStack, so I created this primitive package.
We have a lot of such helpful packages in solid-primitives and are always happy about content users and feature requests.
For anyone coming across this thread, this is how I use it:
@lexlohr is the "invalidate response before refetching" part required? or will calling
refetch
automatically invalidate, somehow?No, at the moment, there is no such automatism.
The question would be why you don't make this a global store resource?
You can just export it and enjoy fine-grained reactivity. Or for even more performance, you could use https://solid-primitives.netlify.app/package/static-store for the storage option of createResource.
Solid Primitives
A library of high-quality primitives that extend SolidJS reactivity
Maybe I should add something convenient to the resource package to use that directly.
That doesn't work with solid-start SSR unfortunately
Ah, you'd need to wrap this in onmount then.