英文:
Can zustand be used in backend projects? Or is it only suited for frontend applications?
问题
Sure, here's the translation:
我正在使用Nest JS进行后端开发,我有一些需要在整个应用程序中保持的全局变量。我的第一选择是redux,但这些变量并不是很大也不是很复杂,所以我计划尝试与之一起使用zustand。
zustand是否可以用于后端应用程序,或者它在优化用例上是否依赖于前端hooks?
英文:
I am using Nest JS for backend development and I have some global variables that need to be stored throughout the app. My first choice was redux but these variables aren't very big and complicated so I was planning to try zustand with it.
Can zustand be used with a backend application or it relies a lot on frontend hooks for optimization use cases?
答案1
得分: 1
这主要用于前端开发。有使用它与SSR的选项,例如官方示例。
我认为在服务器端进行React状态管理有点棘手,尤其是在具有水平扩展/负载均衡器的情况下 - 不能保证来自前端的下一个请求会发送到应用程序的同一实例,因此更好的方法是将服务器端实现为一组无状态函数,并将所有内容传递到请求中。关于"无状态REST API"的一个结果,附带简要解释。
英文:
It's mostly for frontend development only. There are options to use it with SSR, for instance official example.
I see the react state management on the server side a bit tricky, especially having the horizontal scaling/load-balancer - the is no guarantee that the next request from the FE goes to the same instance of the application, so the better approach is to implement server-side as a set of stateless function, passing everything in the request. One of the results for "Stateless REST API" with a short explanation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论