我有一个应用程序,其中包含许多使用 redux 的文件,没有问题。我创建了一个带有减速器和选择器的新数据文件,并使用根减速器注册了它。
如果我在一个文件中使用这些命令,它工作正常......
import { getSubs } from '../state/subs/selectors';
const subs = useSelector(getSubs);
但是,如果我在不同的文件中使用它们,则会出现运行时错误
Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>
第二个文件是有效文件的子文件。这是问题吗?包装需要直接吗?如果是这样,是否有解决方法?
更新:应用程序使用 next.js,我想知道这是否与问题有关。这是包装的地方。
import { wrapper } from '../state/store';
const App = ({ Component, pageProps }) => (
<Layout>
<Component {...pageProps} />
</Layout>
);
App.propTypes = {
Component: PropTypes.func,
pageProps: PropTypes.object,
};
export default wrapper.withRedux(App);