android - React Native 中 redux over normal state 机制的用例

标签 android ios react-native redux react-redux

我正在开发 React Native 应用程序。我遇到了用于应用程序状态管理的 redux。

假设我的应用程序中有欢迎游览,这应该是一次查看 Activity 。我可以将其保存为正常状态并 checkin 我的组件。

这也可以使用 redux 来实现,那么 redux 与正常状态有何不同。任何用例?

最佳答案

React Native 中的 Redux 与普通 React 应用程序中的 Redux 没有什么不同,因此所有关于 Redux 与本地状态的建议都适用。

引用 Redux 文档:

Using local component state is fine. As a developer, it is your job to determine what kinds of state make up your application, and where each piece of state should live. Find a balance that works for you, and go with it.

Some common rules of thumb for determining what kind of data should be put into Redux:

  • Do other parts of the application care about this data?
  • Do you need to be able to create further derived data based on this original data?
  • Is the same data being used to drive multiple components?
  • Is there value to you in being able to restore this state to a given point in time (ie, time travel debugging)?
  • Do you want to cache the data (ie, use what's in state if it's already there instead of re-requesting it)?

引用 Redux 作者 Dan Abramov 的话:

If you’re just learning React, don’t make Redux your first choice. Instead learn to think in React. Come back to Redux if you find a real need for it, or if you want to try something new. But approach it with caution, just like you do with any highly opinionated tool.

还有我最喜欢的:

The rule of thumb is: do whatever is less awkward.

来源:

关于android - React Native 中 redux over normal state 机制的用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46609838/

相关文章:

android - 如何恢复丢失的 keystore 文件别名?

iphone - 同时可拉伸(stretch)和图案化 UIImage

iphone - 检查导航堆栈上的 ViewController 是否存在

android - react 原生无法构建Android APK。 gradlew clean和…命令失败

serialization - 在 React Native 中将 boolean 值存储/保存在 AsyncStorage 中

android - 在 fragment 中垂直居中 RecyclerView

android - 在android中以编程方式显示/隐藏闹钟图标

ios - 使用 Facebook SDK 进行身份验证后转到下一个 View

react-native - 可触摸元素(如按钮、TouchableHighlight 等)在 FlatList 中不起作用

android - 如何在android中添加按钮?