简体   繁体   English

React Redux 商店设置:错误:找不到“商店”

[英]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.

相关问题 React-redux:找不到“商店” - React-redux: Could not find “store” React-Redux / Jest Invariant Violation:找不到“商店” - React-Redux/Jest Invariant Violation: Could not find “store” 在“ Connect(MyComponent)”的上下文中找不到“商店”? Redux反应问题 - Could not find “store” in the context of “Connect(MyComponent)” ? Redux-React Problem React-Native(redux)错误:在“Connect(App)”的上下文中找不到“store” - React-Native (redux) error: Could not find "store" in context of "Connect(App)" 反应错误:“在……的上下文中找不到‘商店’” - React error: "could not find the 'store' in the context of ..." redux 未捕获的不变违规:在上下文中找不到“存储” - redux Uncaught Invariant Violation: Could not find “store” in the context React Native(Netflix App)Android构建错误-“在Connect(App)的上下文或道具中找不到&#39;store&#39;” - React Native (Netflix app) Android build error - “Could not find 'store' in either the context or props of Connect(App)” 使用redux存储访问来创建createBottomTabNavigator - React createBottomTabNavigator with redux store access React + Redux不更新存储 - React + Redux does not update store Redux Store未连接到React组件 - Redux Store not connected to React Component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM