What to use to manage state in T3 stack app

I want to implement a cart function for my app and was wondering what state management library to use with my app. It is made with create-t3-app
28 Replies
barry
barry2y ago
whatever you want zustand is my go to
Halu
Halu2y ago
i mean, if you dont want to get held up you can simply use a composable useState with some mutation helpers. then when you run into specific problems, you have a better idea of what solutions you specifically need. for example, a simple on-demand service may be satisfied with just useState. others with limited inventory may not and need server communication to sync available stock between all clients. And you may want session persistence, so you have to store state in local storage and validate that their stock claim hasnt expired in their next session. theres many ways to build something as simple as a cart. its hard to say what you specifically will need until you run into issues or define things more rigorously
aditya
aditya2y ago
so theres no library in the t3 bundle for this
Halu
Halu2y ago
theres no universal answer for this
aditya
aditya2y ago
I'll have to go with zustand yes i understand now thanks for explaining!!
barry
barry2y ago
no we don't want to choose this for you too many options
aditya
aditya2y ago
ohh i was thinking like there is some library that fits w the libraries of t3
Leonidas
Leonidas2y ago
There are a lot - there is no objective best solution. Many people prefer different solutions. In case you have never had this issue before stick with zustand or plain react context
aditya
aditya2y ago
yeah ig i have to learn zustand
esponges
esponges2y ago
It's very simple if you've ever Redux, and if you don't, it still easy I have a test app for e-commerce with suztand if you want to take a look at https://github.com/esponges/t3-ecommerce
aditya
aditya2y ago
oh wow thats really helpful thanks
esponges
esponges2y ago
my pleasure
aditya
aditya2y ago
i was looking through your app its nicely done i have a few questions... 1. Ive seen the tuts on zustand where I only have to create a store file but you have made 2 files(useCartItems and useCartStore) to my understanding the first one is for accessing the cart info(?) and the second is for updating or editing the cart 2. I was implementing the remove items from cart feature but following the code I cannot get it to work
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
esponges
esponges2y ago
useCartItems is a custom hook that gets the cart items from useCartStore which is the actual Zustand slice :).
Want results from more Discord servers?
Add your server