【发布时间】:2020-07-06 14:27:24
【问题描述】:
import React, { Component } from 'react';
import FormUserDetails from './FormUserDetails';
export class UserForm extends Component {
state = {
Step: 1,
firstName: '',
lastName: '',
email: '',
occupation: '',
city: '',
bio: '',
};
// next step
nextStep = () => {
const { step } = this.state;
this.setState({
step: step + 1,
});
};
// go back to previous
Step = () => {
const { step } = this.state;
this.setState({
step: step - 1,
});
};
// handle field
handleChange = input => e => {
this.setState({ [input]: e.target.value });
};
render() {
const { step } = this.state;
const { firstName, lastName, email, occupation, city, bio } = this.state;
const values = { firstName, lastName, email, occupation, city, bio };
switch (step) {
case 1:
return (
<FormUserDetails
nextStep={this.nextStep}
handleChange={this.handleChange}
values={values}
/>
);
case 2:
return <h1>FormPersonalDetails</h1>;
case 3:
return <h1>Confirm</h1>;
case 4:
return <h1>Success</h1>;
}
}
}
export default UserForm;
【问题讨论】:
标签: reactjs