我是新来的反应,我想使用带有路由的redux(带有redux-react-hook)的react hooks(我使用connected-react-router,但我可以切换到另一个lib)
我将商店传递给 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 不兼容?