我是个新手,我想在路由中使用带有redux(带有redux-react-hook)的react钩子(我使用connected-react-router,但是我可以切换到另一个库)
我将商店传递给StoreContext Provider,一切正常,但是当我添加具有正确上下文的ConnectedRouter时,我会出错。
这就是我正在尝试的
//index.js
import { Route, Switch } from 'react-router-dom';
import { ConnectedRouter } from 'connected-react-router';
import { StoreContext, store, history } from './store';
ReactDOM.render((
<StoreContext.Provider value={store}>
<ConnectedRouter history={history} context={StoreContext}>
<Switch>
<Route path="/" component={App}></Route>
</Switch>
</ConnectedRouter>
</StoreContext.Provider>
), document.getElementById('root'));
//store.js
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import { applyMiddleware, createStore } from 'redux';
import { create } from 'redux-react-hook';
import { routerMiddleware } from 'connected-react-router';
import { createBrowserHistory } from 'history';
import {promiseMiddleware } from './middlewares'
import createRootReducer from './reducer'
export const { StoreContext, useDispatch, useMappedState } = create();
export const history = createBrowserHistory();
export const store = createStore(
createRootReducer(history),
{}, //preloadedState
composeWithDevTools(applyMiddleware(
routerMiddleware(history),
promiseMiddleware
))
);
但是我收到此错误:
TypeError: sourceSelector is not a function
Connect.selectDerivedProps
C:/Users/NG7F61C/Documents/PROJECTS/1 - IJET/Sources/frontend/node_modules/react-redux/es/components/connectAdvanced.js:112
109 |
110 | lastProps = props;
111 | lastState = state;
> 112 | var nextProps = sourceSelector(state, props);
| ^ 113 | lastDerivedProps = nextProps;
114 | return lastDerivedProps;
115 | };
我做错了还是ConnectedRouter与redux-react-hook不兼容?