当前位置 : 主页 > 网页制作 > React >

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

来源:互联网 收集:自由互联 发布时间:2021-06-15
说,我不想让我的复选框状态保存在全局redux商店中.因为我不想处理这个小地方国家的行动和减少者.所以我想在我的组件中明确使用setState(). 这是一种不好的做法(例如,在测试方面)? 按
说,我不想让我的复选框状态保存在全局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)?
网友评论