比如说,我不想在全局 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/