React tutorial series的中途,并在mapStateToProps的末尾收到错误。据我所知,我的代码与教程中的代码相同。
在命令行中:
> npm run build
> SyntaxError: /home/jake/web/flashcards/src/components/App.js: Unexpected token (5:22) while parsing file: /home/jake/web/flashcards/src/components/App.js
这是App.js:
import React from 'react';
import Sidebar from './Sidebar';
import {connect} from 'react-redux';
const mapStateToProps (props, {params:{deckId}}) => ({
deckId
});
const App = ({deckId, children}) => {
return(<div className ='app'>
<Sidebar />
<h1> Deck {deckId} </h1>
{children}
</div>);
};
export default connect(mapStateToProps)(App);
我的package.json:
{
"name": "flashcards",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "watchify src/app.js -o public/bundle.js -t [ babelify --presets [ react es2015 ] ]",
"server": "cd public; live-server --port=1236 --entry-file=index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babelify": "^7.3.0",
"live-server": "^1.2.0",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-redux": "^5.0.4",
"react-router": "^3.0.2",
"react-router-redux": "^4.0.8",
"redux": "^3.6.0",
"watchify": "^3.9.0"
}
}
答案 0 :(得分:2)
缺少等号:
const mapStateToProps = (props, {params:{deckId}}) => ({
deckId
});
答案 1 :(得分:1)
const声明中的初始化器
const mapStateToProps =
^^