[英]React node app - is it better to store property is watched (item is watched) in frontend or backend?
I have a watchlist, where user can add items to.我有一个监视列表,用户可以在其中添加项目。 I want to either show add button or string 'item is already on watchlist'.
我想显示添加按钮或字符串“项目已在关注列表中”。 is it better to store that isWatched prop on frontend or backend?
将 isWatched 道具存储在前端还是后端更好? on frontend: I already do fetch watchlist.
在前端:我已经获取了关注列表。 I can put make it global using for example context, then I could have an array of id's of watched items in my global store and pass it to components that checks 'isWatched'.
我可以使用例如上下文将其设为全局,然后我可以在我的全局存储中拥有一组已监视项目的 id,并将其传递给检查“isWatched”的组件。 on backend: I could add it (isWatched prop) the to item in my product collection.
在后端:我可以将它(isWatched prop)添加到我的产品集合中的项目。 then when user opens the product item, the prop isWatched is already there.
然后当用户打开产品项目时,道具 isWatched 已经存在。 no fetching needed.
无需获取。
What is good practise to/where store such properties?存储此类属性的良好做法是什么? Thank you
谢谢
If you want the user to get the same results from a different browser - you should persist it on the backend side.如果您希望用户从不同的浏览器获得相同的结果 - 您应该将其保留在后端。 If not - then you can keep it on the FE side.
如果没有 - 那么您可以将其保留在 FE 方面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.