ここに反応します。 code snippetでは、を避けるために、関数handleChange
をES6スタイルに変更すると、の後に=
にエラーが発生します。なぜだろう。Reactjs私のコードスニペットのES6構文エラー
===あなたが割り当てた後にセミコロンが欠落している私の変更==
function BoilingVerdict(props) {
if (props.celsius >= 100) {
return <p>The water would boil.</p>;
}
return <p>The water would not boil.</p>;
}
class Calculator extends React.Component {
constructor(props) {
super(props);
//this.handleChange = this.handleChange.bind(this);
this.state = {temperature: ''};
}
handleChange = (e) => {
this.setState({temperature: e.target.value});
}
render() {
const temperature = this.state.temperature;
return (
<fieldset>
<legend>Enter temperature in Celsius:</legend>
<input
value={temperature}
onChange={this.handleChange} />
<BoilingVerdict
celsius={parseFloat(temperature)} />
</fieldset>
);
}
}
ReactDOM.render(
<Calculator />,
document.getElementById('root')
);
どのようなエラーが表示されますか?私は割り当て後にセミコロンがないと信じています。 – Sulthan
@Sulthanさん、ありがとうございました。まさにエラーの原因です。私はいつも必要というわけではないので、JSでは ';'を持たないことに慣れてきました。あなたが回線の回答を書き留めたら、私はそれを受け入れます! – pktCoder