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
whatever you want
zustand is my go to
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
so theres no library in the t3 bundle for this
theres no universal answer for this
I'll have to go with zustand
yes i understand now
thanks for explaining!!
no we don't want to choose this for you
too many options
ohh i was thinking like there is some library that fits w the libraries of t3
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
yeah ig i have to learn zustand
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
oh wow thats really helpful thanks
my pleasure
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•2y ago
Message Not Public
Sign In & Join Server To View
useCartItems
is a custom hook that gets the cart items from useCartStore
which is the actual Zustand slice :).