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