我正在尝试将redux设置到我的react项目中,当我使用connect函数并将其包装在组件周围时,会弹出此错误。
我尝试遍历文档,并根据我的知识执行每个步骤,但错误似乎总是会发生
Routes.js
import {connect} from 'react-redux';
class Routes extends React.Component {
}
const mapStateToProps = (state) => {
return {
posts: state
}
}
export default connect(mapStateToProps)(Routes)
rootReducer.js
const initialState = {
posts: [
{id: 1, data: "Hello There"},
{id: 2, data: "Hello There Nav"},
{id: 3, data: "Hello There Mon"}
]
};
const rootReducer = (state = initialState, action) => {
return state;
};
export default rootReducer;
index.js
import {createStore} from 'redux';
import {Provider} from 'react-redux';
import rootReducer from './reducers/rootReducer';
const store = createStore(rootReducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
ReactDOM.render(<Provider store={store}><Routes><App /></Routes></Provider>, document.getElementById('root'));