【发布时间】:2019-11-10 08:09:31
【问题描述】:
我有一个 NextJS React 应用程序,它在 _app.tsx 上使用 next-react-wrapper(基本上是一个 HOC),如下所示:
_app.tsx
...
import withRedux from 'next-redux-wrapper';
class Page extends App<Props> {
...
}
export default withRedux(reduxStore)(Page);
store.ts
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import rootReducer from './reducer';
export default (
initialState: any = undefined,
) => createStore(
rootReducer,
initialState,
composeWithDevTools(applyMiddleware()),
);
我正在努力研究如何在 React 之外访问商店,例如在一个简单的帮助函数中。我的 store.ts 文件导出了一个 makeStore 函数,它是 next-redux-wrapper HOC 所需的(包括初始状态)。
我可以在 React 组件中访问 store,每次都将它作为参数传递给我的辅助函数,但这看起来很混乱。
有没有办法直接从非 React 辅助功能模块访问 store?
【问题讨论】:
标签: javascript reactjs redux next.js next-redux-wrapper