Zustand是否可用于后端项目?还是只适用于前端应用程序?

huangapple go评论88阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月14日 11:49:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定