import React from 'react'; import { withRouter } from 'react-router-dom'; class SessionForm extends React.Component { constructor(props) { super(props); this.state = this.props.loginInfo; this.handleSubmit = this.handleSubmit.bind(this); } renderErrors(errors) { const loginErrors = document.getElementById("login-errors") while (loginErrors.firstChild) { loginErrors.firstChild.remove(); } loginErrors.appendChild(document.createTextNode(errors.errors.responseJSON)) } handleSubmit(e) { e.preventDefault(); this.props.login(this.state).then( null, errors => this.renderErrors(errors) ); } handleChange(field) { return e => this.setState({[field]: e.target.value}); } render() { return (
); } } export default withRouter(SessionForm);