when would I need state management like redux in my e commerce app?

I am new to React and web development generally so please try to understand if the question seems dumb.

So, I am currently making a simple e-commerce app and I was thinking of using state management either using redux or react context.

However, I also thought if I have a database, why would I need global state management if I can retrieve the data or sessions I need from the database? For example, if need cart information for the currently logged-in user, I can retrieve it from the database, if I want information related to the order list, I can retrieve it from the database.

I know I am missing something because it doesn’t sound right to completely avoid using state management tools but at this point, I just don’t know when will I need such state management specifically in e-commerce.

Can you please tell me if there are situations where I would need to use state management?

In a nutshell, the client app states have little to do with the business data. Of course, some business data might be referred or held by the client’s state, but it’s contextual. Not mandatory.

When we refer to the client app state, we think about the last page visited, the last button clicked, pre-filled and unsubmitted forms, the number/badge of items in the cart, the number/badge of notifications in the built-in message inbox, etc. It’s somewhat a snapshot of the client at a given point in time.

For example, say the user was searching for products, filling the cart and, at some point, it goes afk; the token/session expires. When the user is back, the shop redirects to the login page. Allowing the user to continue with his/her activity/process from where it was haltered, will take you to “remember” a few things like: the last page, the last search, items in the cart, etc. By doing so, after the login, the app can fetch all this info and lead the user to the precise app state he/she was before going afk.

If you have multiple clients (web, mobile, tablet, smartwatch, etc.) and you want them to share the state, then the state can not be held by the client apps individually; it has to be sent to the server to allow other clients to synch and reproduce the same state. Whether the server persists this data in a database or in memory is an implementation detail.

Another use case is the offline mode. Say one of the clients goes offline due to connectivity issues. By managing the state on the client side, you allow the user to keep “buying” (filling the cart) until the connection is back or stable and the current state can be synced with other clients through the server.

Note that all of this is only relevant when the server (backend) is stateless or we want it to be so. No need to say that server and client states aren’t and don’t need to be the same. That’s another good reason for managing the client app state on the client side, to keep server-side complexity low.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật