Redux:如何为单独的子 React 组件创建新的 Redux 存储

Redux: How to create a new Redux store for separate child react components

我有一个要导入到我的项目中的 React 组件。我的主项目和组件都使用单独的 redux 存储。最初该组件只导入一次,这没有问题,但是当它导入两次时,它对两个子组件使用相同的 redux 存储。

如何确保从同一个库导入的两个使用 redux 的子项,每个子项都使用一个单独的 redux 存储?或者,什么是更好的解决方案?我尝试重构商店的使用方式,但运气不佳。

在日志中我可以看到 redux 存储仅在页面加载时初始化一次。

Redux 是一个全球商店。它旨在用作 one store per application. While there are ways around that, documented here under "custom context",强烈建议不要这样做。 如果您使用相同的道具两次使用相同的组件,它也应该使用完全正确的数据。如果不是这样,you likely should not be using a global state from the beginning, but keep that state as component-local state in those two components.