Не могу нормально получить данные по отправке формы, использую библиотечку material ui
import React from 'react';
import ReactDOM from 'react-dom';
import TextField from 'material-ui/TextField';
import RaiseButtin from 'material-ui/RaisedButton';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
const style = {
button: {
margin: 12
},
exampleImageInput: {
cursor: 'pointer',
position: 'absolute',
top: 0,
bottom: 0,
right: 0,
left: 0,
width: '100%',
opacity: 0,
}
};
class UserForm extends React.Component{
constructor(props){
super(props);
this.state = {login: '', password: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e){
this.setState = ({login: e.target.login, password: e.target.password});
}
handleSubmit(e){
e.preventDefault();
alert(`login: ${this.state.login} password: ${this.state.password}`);
}
render(){
return(
<div>
<form onSubmit={this.handleSubmit}>
<Fields text="Введите логин" type="text" value={this.state.login} onChange={this.handleChange}/>
<Fields text="Введите пароль" type="password" value={this.state.password} onChange={this.handleChange}/>
<MuiThemeProvider>
<RaiseButtin label="Войти" fullWidth={true} style={style.button}> <input type="submit" style={style.exampleImageInput}/> </RaiseButtin>
</MuiThemeProvider>
</form>
</div>
);
}
}
class Fields extends React.Component{
constructor(props){
super(props);
}
render(){
return(
<MuiThemeProvider>
<div>
<TextField
hintText={this.props.text}
type={this.props.type}
/>
</div>
</MuiThemeProvider>
);
}
}
ReactDOM.render(
<UserForm />,
document.getElementById('content')
);
Вот в песочнице
https://codepen.io/rusline/pen/aEmKVa