加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 09:32:24 所属栏目:百科 来源:网络整理
导读:说,我不想让我的复选框状态保存在全局redux商店中.因为我不想处理这个小地方国家的行动和减少者.所以我想在我的组件中明确使用setState(). 这是一种不好的做法(例如,在测试方面)? 解决方法 按 Redux FAQ entry on component state vs Redux state: Using l
说,我不想让我的复选框状态保存在全局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)?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读