以下のコードで9行目にエラーが表示されます
構文エラー:予期しないトークン(9:10)このコードの問題とその修正方法を教えていただけますか?react jsxコンポーネントのコンパイルの問題
import React from 'react';
import {SelectField, MenuItem, getMuiTheme, MuiThemeProvider,Stepper,Step,StepLabel,StepButton,StepContent} from 'material-ui'
import injectTapEventPlugin from 'react-tap-event-plugin';
import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';
class StepperComponent extends React.Component{
state = {
stepIndex: 0,
}
handleNext =() => {
const {stepIndex} = this.state;
if (stepIndex < 2) {
this.setState({stepIndex: stepIndex + 1});
}
};
handlePrev =() => {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.setState({stepIndex: stepIndex - 1});
}
};
renderStepActions(step) {
return (
<div style={{margin: '12px 0'}}>
<RaisedButton
label="Next"
disableTouchRipple={true}
disableFocusRipple={true}
primary={true}
onTouchTap={this.handleNext}
style={{marginRight: 12}}
/>
{step > 0 && (
<FlatButton
label="Back"
disableTouchRipple={true}
disableFocusRipple={true}
onTouchTap={this.handlePrev}
/>
)}
</div>
);
}
render() {
const {stepIndex} = this.state;
return (
<div style={{maxWidth: 380, maxHeight: 400, margin: 'auto'}}>
<MuiThemeProvider muiTheme={getMuiTheme}>
<Stepper
activeStep={stepIndex}
linear={false}
orientation="vertical"
>
<Step>
<StepButton onClick={() => this.setState({stepIndex: 0})}>
GROUP NAME
</StepButton>
<StepContent>
<p>
Add group name and description selection component here
</p>
{this.renderStepActions(0)}
</StepContent>
</Step>
<Step>
<StepButton onClick={() => this.setState({stepIndex: 1})}>
STUDENT
</StepButton>
<StepContent>
<p> Add student component here </p>
{this.renderStepActions(1)}
</StepContent>
</Step>
<Step>
<StepButton onClick={() => this.setState({stepIndex: 2})}>
VERIFY
</StepButton>
<StepContent>
<p>
Add verify group component here
</p>
{this.renderStepActions(2)}
</StepContent>
</Step>
</Stepper>
</MuiThemeProvider>
</div>
);
}
}
export default StepperComponent;
以下の代替構文を使用すると、コンパイルエラーは発生しませんが、何らかの理由でボタンクリックイベントが機能しません。
constructor(props) {
super(props);
this.state = {
stepIndex: 0,
};
}
handleNext() {
const {stepIndex} = this.state;
if (stepIndex < 2) {
this.setState({stepIndex: stepIndex + 1});
}
};
handlePrev() {
const {stepIndex} = this.state;
if (stepIndex > 0) {
this.setState({stepIndex: stepIndex - 1});
}
};
私は修正案を提案しましたが、それでもまだ動作していないものもあります。可能であれば、実際のサンプルのJSFiddleを提供してください。これは材料Uiのウェブサイトhttp://www.material-ui.com/#/components/stepperのコードです。垂直非線形ステッパーをチェックしてください。例。 – Sachin
動作していないもの(エラー/警告...)を詳しく説明できますか? – Pineda
ボタンのいずれかでクリックイベントが発生していません。 – Sachin