[英]React Redux Store setup: Error: Could not find “store”
I am trying to setup react-redux store here, and i have error message in browser:我正在尝试在此处设置 react-redux 存储,并且在浏览器中出现错误消息:
Error: Could not find "store" in the context of "Connect(Card)".错误:在“Connect(Card)”的上下文中找不到“store”。 Either wrap the root component in a < Provider >, or pass a custom React context provider to and the corresponding React context consumer to Connect(Card) in connect options.要么将根组件包装在 <Provider> 中,要么将自定义的 React 上下文提供者传递给连接选项中的 Connect(Card),并将相应的 React 上下文消费者传递给。
Index.js索引.js
import React from 'react';
import ReactDOM from 'react-dom';
import {createStore} from "redux";
import reducer from "./Store/reducer";
import {Provider} from "react-redux";
const store = createStore(reducer);
ReactDOM.render(
<Provider store={store}>
<App/>
</Provider>,
document.getElementById('root'));
App.js应用程序.js
import React from 'react';
import Counter from "../counter";
const App = props => {
return (
<div className="App">
<Counter/>
</div>
);
};
export default App;
Counter.js计数器.js
import connect from "react-redux/lib/connect/connect";
import Card from "../Components/Card";
import React from "react";
const Counter = (Card);
const mapStateToProps = state => {
return {
ctr: state.counter
};
};
export default connect(mapStateToProps)(Counter);
reducer.js减速器.js
import {combineReducers} from "redux";
const initialState = {
counter: 0
};
const reducer = (state = initialState, action) => {
return state;
};
export default reducer
This is a really simple setup and i am not sure where went wrong, please help.这是一个非常简单的设置,我不确定哪里出了问题,请帮忙。
Simply import connect from react-redux:只需从 react-redux 导入连接:
import { connect } from 'react-redux'
And why are you messing with Card component being used in Counter component.以及为什么要弄乱 Counter 组件中使用的 Card 组件。 Why don't you directly use to connect there in Card component?为什么不在 Card 组件中直接使用连接呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.