Replies: 1 comment 2 replies
-
@ardeora thanks for bringing up this discussion about the API surface. It think it feels intuitive for SolidJS devs that the query key is a function. It was my first thought how a Solid API could look like. ImplementationRegarding the implementation about the query state in I think it's useful to discuss other details about the implementation in your repository. We should also create a feature list that is needed to be feature complete and track the state in separate issues. What do you think? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Everyone!
Hope everyone is having a great week. I have been working on the Solid JS Adapter for TanStack Query. I wanted a place to discuss my motivations for the patterns I have adapted as of now. I also want this discussion to serve as a place for folks to offer feedback/contribute so that we can make
solid-query
helpful for all use cases.Query Keys in
solid-query
? 🤔One challenge that needed to be addressed as I started out was making the queryKey reactive.
If you're familiar with
react-query
. The query key is an array used to keep track of the query in theQueryClient
cache. Whenever any of the items in the query key change, React Query treats it as a new query and will fetch new data.Unlike react, Solid Component functions are usually executed once. and component states are responsible for making themselves reactive using
Signals/Stores
. In order to implement the same behaviour withsolid-query
, we can do something like:NOTE: We are passing the signal Accessor function
page
instead of the signal's valuepage()
in the query. Why? Let's assume we define the queryKey as['users', page()]
. This query key will work for the initial query. But when we update thepage
signal, thequery
object will still show page 1's data. This happens because the query key was instantiated as['users', 1]
and the queryKey array is not reactive. Therefore, providing the Accessor function tellssolid-query
which signals it needs to track for changes.Wait, but what if my
queryKey
is derived from a calculation on a signal? 😱With the previous approach, For example, you wont be able to do something like this:
So what's the solution here? This is where
solid-query
differs fromreact-query
a little bit. Solid Query allows users to also pass a function that returns an array as aqueryKey
. This will allow users to also be able to use derived values in theircreateQuery
callsThis above example works fine and is fully reactive!
I wanted to bring these two approaches to attention in this discussion here. I would love some feedback on whether this approach makes sense for people as well as offers them flexibility to use
createQuery
however they like. I would be more than happy to make changes if there are flaws that I missed. I would love your contributions on the GitHub repo linked here: ardeora/solid-queryExample 1:
createQuery
I was able to implement the
createQuery
function forsolid-query
and have a working example for it working here. This is a simple table that gets users from an API and offers buttons to paginate through the table. Give it a spin and let me know if you have questionshttps://stackblitz.com/edit/vitejs-vite-nvkeub?file=src%2FTable.tsx
Next Steps:
I will be working on creating the
createMutation
function next. Again, would love to collaborate with folks in the SolidJS Community.Beta Was this translation helpful? Give feedback.
All reactions