微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

reactjs – 绕过redux使用有状态组件是不好的做法?

说,我不想让我的复选框状态保存在全局redux商店中.因为我不想处理这个小地方国家的行动和减少者.所以我想在我的组件中明确使用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)?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐