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

Is it a bad practice to use stateful components bypassing redux?

说,我不想在全局 redux 存储中保留我的复选框状态。因为我不想处理这个小型本地状态的动作和缩减器。所以我想在我的组件中明确使用 setState()

是否是一种不良做法(例如,在测试方面)?

只要不依赖于数据,将复选框状态保持在本地状态绝对没问题。

一个好的做法是将所有数据保存在 redux 存储中,并将 ui 相关状态保存在本地存储中。

根据 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)?