简体   繁体   English

在./src/App.js'store'中的反应错误未定义

[英]react Error in ./src/App.js 'store' is not defined

attempting to follow this tutorial https://thinkster.io/tutorials/setting-up-react-redux/introducing-react-redux 尝试按照本教程https://thinkster.io/tutorials/setting-up-react-redux/introducing-react-redux

App.js file- App.js文件 -

import React from 'react';
import { connect } from 'react-redux';

const mapStateToProps = state => ({
  appName: state.appName
});

class App extends React.Component {
  render() {
    const onClick = () => store.dispatch({ type: 'TOGGLE' });
    return (
      <div>
        { this.props.appName }
      </div>
    );
  }
}

export default connect(mapStateToProps, () => ({}))(App);

according to the video, by importing the connect function and defining mapStateToProps we will get access to store. 根据视频,通过导入connect函数并定义mapStateToProps,我们将获得对store的访问权限。 it does not work. 这是行不通的。

also, the code in the video is different from the code in the guide. 此外,视频中的代码与指南中的代码不同。 so at this point i'm not sure if i'm doing something incorrectly, or if this guide is just bad. 所以在这一点上我不确定我是不是做错了什么,或者这个指南是不是很糟糕。 can anyone suggest a better guide for learning react? 任何人都可以建议更好的学习反应指南吗?

full error message- 完整的错误信息 -

Failed to compile. 编译失败。

Error in ./src/App.js ./src/App.js出错

c:\\Sites\\react_frontend\\django-frontend\\src\\App.js C:\\网站\\ react_frontend \\ Django的前端的\\ src \\ App.js

14:11 warning 'onClick' is assigned a value but never used no-unused-vars 14:11警告'onClick'被赋值,但从未使用过no-unused-vars

14:27 error 'store' is not defined no-undef 14:27错误'store'未定义no-undef

✖ 2 problems (1 error, 1 warning) ✖2个问题(1个错误,1个警告)

This tutorial is not very good - a lot of things are missing. 本教程不是很好 - 很多东西都缺失了。

A previous step had the following line: 上一步有以下几行:

const store = createStore(reducer);

I am also using Thinkster and the line below worked for me. 我也在使用Thinkster,下面这一行为我工作。 I found that there is no need to provide the empty object at all. 我发现根本不需要提供空对象。

export default connect(mapStateToProps)(App);

I agree with you that the react redux tutorial is quite poorly done. 我同意你的看法,react redux教程做得很差。 I found that the Backend Tutorials(Express and mongo) was a lot more cohesive than the front end. 我发现后端教程(Express和mongo)比前端更具凝聚力。 The tutorials linked together well and each one started where the other left off. 这些教程很好地连接在一起,每个教程都从另一个停止的地方开始。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [eslint] src\App.js 第 2:8 行中的 React js 错误警告:'person' 已定义但从未使用过 - React js error WARNING in [eslint] src\App.js Line 2:8: 'person' is defined but never used 如何在React“ ./src/components/App.js&#39;Layout&#39;,&#39;Home&#39;中定义组件错误,未定义react / jsx-no-undef - How to fix component error in React "./src/components/App.js 'Layout', 'Home' is not defined react/jsx-no-undef React js:./src/App.js第22行:未定义&#39;lastWinner&#39;no-undef搜索关键字以了解有关每个错误的更多信息 - React js: ./src/App.js Line 22: 'lastWinner' is not defined no-undef Search for the keywords to learn more about each error ./src/App.js Line 6:19: &#39;Component&#39; 未定义 no-undef - ./src/App.js Line 6:19: 'Component' is not defined no-undef 反应错误-./src/App.js第16行:解析错误:意外的令牌 - React error - ./src/App.js Line 16: Parsing error: Unexpected token 反应错误“ ./src/App.js第7行:&#39;APIKEY&#39;被分配了一个值,但从未使用过no-unused-vars” - React error “./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars” ReactJS:语法错误:src / App.js:意外令牌(16:6) - ReactJS :Syntax error: src/App.js: Unexpected token (16:6) 我定义了组件并使用它 App.js 但出现未定义的错误 - I defined component and used it App.js but getting undefined error 引用的错误:app.js第1行中未定义angular - Referenced Error: angular is not defined in app.js line 1 src\\App.js &#39;nav&#39; 已定义但从未使用过 no-unused-vars - src\App.js 'nav' is defined but never used no-unused-vars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM