在 AsyncStorage 或 redux 中存储全局数据的最佳方式? [英] Best way to store global data in AsyncStorage or redux?

查看:38
本文介绍了在 AsyncStorage 或 redux 中存储全局数据的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个功能,比如我想在多个屏幕中使用的数据的购物车.此外,想要管理查看购物车和清除购物车项目,但仅限本地.推荐的方式是什么?

I am developing a feature like a cart of which data I want to use in multiple screens. Also, want to manage the view cart and clear cart items but locally only. What is the recommended way to go with?

1) 异步存储2) 还原

1) AsyncStorage 2) Redux

请帮助我,如果我有任何误解,请告诉我.

Kindly help me and let me know if there is a misconception on my side.

推荐答案

AsyncStorage 和 Redux 有不同的用途.

AsyncStorage and Redux serve different purposes.

AsyncStorage 允许您存储应用实例之间(即应用重启之间)持久化的数据.

AsyncStorage is there to allow you to store data that is persisted between app instances (that is, between restarts of your app).

Redux 是一个状态管理系统,旨在解决在 React 中围绕组件移动状态的问题.

Redux is a state management system that is meant to solve the problem of moving state around components in react.

您所描述的实际上可以同时使用两者,其中 Redux 用于状态管理,而 redux 存储本身可以保存到 AsyncStorage 中以备后用.有一些 Redux 相关库可以做到这一点,例如 Redux-Persist.

What you're describing can actually use both, where Redux is used for state management, and the redux store itself can be saved into AsyncStorage for later use. There are Redux related libraries that do just that, such as Redux-Persist.

这篇关于在 AsyncStorage 或 redux 中存储全局数据的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆