Suggested approach to creating actions
for a store?
#205
Replies: 1 comment
-
Thanks for the great response! As someone interested in TanStack Store, I really appreciate the insights. I agree that the patterns you've outlined work well. However, I think you're absolutely right about not adding built-in actions. Built-in actions would make the library more complex and harder for users to handle in general patterns. In situations like this, I think empowering users to choose their own approach is much better than standardizing a specific pattern or API. The current minimal approach lets developers pick what works best for their team and project, which aligns perfectly with the headless philosophy. Just my personal opinion - thanks for considering it! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying to work out the best pattern for creating actions/methods relating to a store. In most cases, actions are so specific, that in most cases I just end up calling setState directly, but in more complex cases, this will not cut it.
Some of my colleagues have simply structured their code such that actions are exported from the same file
We've also tried another approach to help with intellisense:
And I have personally found it pretty intuitive to simply extend the store (although this is still not ideal since we have to instantiate this new class at the end of the file still;
With this said, none of these seems particularly elegant, since creating random methods in a file is generally not my favourite.
I also know some other store libraries offer a way to do this, something like:
This is... okay, but it doesn't scale too well if you find yourself needing to make more than a couple of methods, or methods that are quite long - since it makes it hard to add on methods by defining them outside of the file in an "actions.ts" file for example.
I'm just wondering:
A) Is there a standard pattern people are using, or that you'd recommend
B) Is there any consideration into adding a first class concept of "actions" into this library?
I understand the requirements of other Tanstack libraries directly relate to what features are added into Tanstack store, so it's completely understandable if actions are not such a requirement, but I am interesting if there is a pattern people are using for this
Beta Was this translation helpful? Give feedback.
All reactions