私はReactを使ってこのデモを書いています。 Webpackを使ってこのデモを作成します。このデモを開始すると、エラーが表示されます。ReactJs、 `static defaultProps`を持つSyntaxError
ERROR in ./src/app.js Module build failed: SyntaxError: Unexpected token (8:24)
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
class Button extends Component {
constructor(props){
super(props);
}
static defaultProps = {
color:'blue',
text: 'Confirm',
}
render(){
return (
<button className={'btn btn-${color}'}>
<em>{text}</em>
<p>This is a button.</p>
</button>
);
}
}
ReactDOM.render(<Button />, document.getElementById('app'));
私は本から、このデモをお読みください。この本のために間違ったコードが印刷されている可能性があります。だから今私はこの質問をする。
エラー表示static defaultProps = {
は正しくありません。この本はまたこの書式で書かれています。あなたは正しいコードを知っていますか?