reactjs - 使用有状态组件绕过 redux 是一种不好的做法吗?

标签 reactjs redux react-redux

比如说,我不想在全局 redux 存储中保留我的复选框状态。因为我不想处理这个小型本地状态的操作和 reducer 。所以我想在我的组件中显式使用 setState()

这是一种不好的做法吗(例如,在测试方面)?

最佳答案

根据 Redux FAQ entry on component state vs Redux state :

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 determing 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)?

关于reactjs - 使用有状态组件绕过 redux 是一种不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43573930/

相关文章:

javascript - 如何通过react-router正确使用嵌套路由?

javascript - react-redux-react-router v4 url​​,更新但组件不更新

css - 我如何在 React 中将组件堆叠在一起?

javascript - 应用范围内的 RTK 查询加载和获取指标

reactjs - 如何使用 react-redux 在功能组件中调用 Action 创建者?

html - 导航栏边距的间距不起作用 react

javascript - 如何将其转换为样式组件以及如何嵌套类

reactjs - Shaka 播放器无法在谷歌浏览器上加载 HLS

angular - 在 angular 2 中的 redux 中执行异步操作的推荐方法

reactjs - 实现 Redux 后基本 React 测试失败