Как сформировать массив с пользователями (list) введенных через форму в стейте?
class SignIn extends Component {
state = {
name: "",
organization: "",
email: "",
current:"",
phone: "",
simulator: "",
error: "",
list: []
};
componentDidMount() {
auth.logout();
}
handleChange = e => {
const { name, value } = e.target;
this.setState({ [name]: value });
};
onSubmit = e => {
e.preventDefault();
const { name } = this.state;
localStorage.clear();
localStorage.setItem("userName", name);
const local = localStorage.getItem("userName");
};
render() {
const { classes } = this.props;
return (
<main className={classes.main}>
<CssBaseline />
<Paper className={classes.paper}>
<form className={classes.form} onSubmit={this.onSubmit}>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="name">Фамилия Имя Отчество</InputLabel>
<Input
id="name"
name="name"
autoComplete="name"
autoFocus
onChange={this.handleChange}
/>
</FormControl>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="organization">Название компании</InputLabel>
<Input
id="organization"
name="organization"
autoComplete="organization"
onChange={this.handleChange}
/>
</FormControl>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="email">E-MAIL</InputLabel>
<Input
id="email"
name="email"
autoComplete="email"
onChange={this.handleChange}
/>
</FormControl>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="current">Должность</InputLabel>
<Input
id="current"
name="current"
autoComplete="current"
onChange={this.handleChange}
/>
</FormControl>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="phone">Телефон</InputLabel>
<Input
id="phone"
name="phone"
autoComplete="phone"
onChange={this.handleChange}
/>
</FormControl>
<FormControl margin="normal" required fullWidth>
<InputLabel htmlFor="simulator">Какой тренажер нужен?</InputLabel>
<Input
id="simulator"
name="simulator"
autoComplete="simulator"
onChange={this.handleChange}
/>
</FormControl>
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
>
Записать пользователя
</Button>
</form>
</Paper>
</main>
);
}
}
export default withStyles(styles)(SignIn);