过滤器选项是否使用 Redux
Using Redux or not for filter options
我是 React Native 的新手(参加过一些课程),现在正在自己构建我的第一个应用程序,进展顺利,但我需要一些关于用户应用的过滤器以及如何处理这个问题的建议。
快速总结需要完成的工作。
用户应该能够设置一些过滤器,以便仅显示某些数据并且即使在关闭应用程序后也会保存此状态,用户再次登录并且仍然只能看到由于过滤器选项而被过滤的数据he/she之前设置的。
在我的一门课程中,我介绍了 Redux,我的问题是我应该为此功能使用 Redux 还是使用 Context?我的数据是从 Firestore 中获取的,我可以使用查询从 Firestore 中过滤数据,但这最终会导致许多 read/writes 花费金钱。
非常欢迎所有建议!
使用 redux
当您在应用程序中全局需要一些静态状态时,请使用打开关闭抽屉等上下文。对于动态状态,请使用 redux
如所述:
As Context is no longer an experimental feature and you can use
Context in your application directly and it is going to be great for
passing down data to deeply nested components which is what it was
designed for.
As Mark Erikson has written in his blog:
If you're only using Redux to avoid passing down props, context could
replace Redux - but then you probably didn't need Redux in the first
place.
Context also doesn't give you anything like the Redux DevTools, the
ability to trace your state updates, middleware to add centralized
application logic, and other powerful capabilities that Redux enables.
Redux is much more powerful and provides a large number of features
that the Context API doesn't provide, also as @danAbramov mentioned
React Redux uses context internally but it doesn’t expose this fact in
the public API. So you should feel much safer using context via React
Redux than directly because if it changes, the burden of updating the
code will be on React Redux and not you.
It's up to Redux to actually update its implementation to adhere with
the latest Context API.
The latest Context API can be used for Applications where you would
simply be using Redux to pass data between components, however
applications which use centralized data and handle API requests in
Action creators using redux-thunk or redux-saga still would need
Redux. Apart from this Redux has other libraries associated with it
like redux-persist which allows you to save/store data in localStorage
and rehydrate on refresh which is what the Context API still doesn't
support.
我是 React Native 的新手(参加过一些课程),现在正在自己构建我的第一个应用程序,进展顺利,但我需要一些关于用户应用的过滤器以及如何处理这个问题的建议。
快速总结需要完成的工作。
用户应该能够设置一些过滤器,以便仅显示某些数据并且即使在关闭应用程序后也会保存此状态,用户再次登录并且仍然只能看到由于过滤器选项而被过滤的数据he/she之前设置的。
在我的一门课程中,我介绍了 Redux,我的问题是我应该为此功能使用 Redux 还是使用 Context?我的数据是从 Firestore 中获取的,我可以使用查询从 Firestore 中过滤数据,但这最终会导致许多 read/writes 花费金钱。
非常欢迎所有建议!
使用 redux 当您在应用程序中全局需要一些静态状态时,请使用打开关闭抽屉等上下文。对于动态状态,请使用 redux
如
As Context is no longer an experimental feature and you can use Context in your application directly and it is going to be great for passing down data to deeply nested components which is what it was designed for.
As Mark Erikson has written in his blog:
If you're only using Redux to avoid passing down props, context could replace Redux - but then you probably didn't need Redux in the first place.
Context also doesn't give you anything like the Redux DevTools, the ability to trace your state updates, middleware to add centralized application logic, and other powerful capabilities that Redux enables.
Redux is much more powerful and provides a large number of features that the Context API doesn't provide, also as @danAbramov mentioned
React Redux uses context internally but it doesn’t expose this fact in the public API. So you should feel much safer using context via React Redux than directly because if it changes, the burden of updating the code will be on React Redux and not you.
It's up to Redux to actually update its implementation to adhere with the latest Context API.
The latest Context API can be used for Applications where you would simply be using Redux to pass data between components, however applications which use centralized data and handle API requests in Action creators using redux-thunk or redux-saga still would need Redux. Apart from this Redux has other libraries associated with it like redux-persist which allows you to save/store data in localStorage and rehydrate on refresh which is what the Context API still doesn't support.