Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
888 B
2
Indexable
Never
import React from 'react';

class Login extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      username: '',
      password: '',
    };
  }

  myChangeHandler = (event) => {
    const { name, value } = event.target;
    this.setState({ [name]: value });
  }

  readState = (event) => {
    event.preventDefault();
    console.log(this.state);
  }

  render() {
    return (
      <div>
        <form>
          <input
            type="text"
            name="username"
            onChange={this.myChangeHandler}
          />
          <input
            type="password"
            name="password"
            onChange={this.myChangeHandler}
          />
          <button
            onClick={this.readState}
            type="button"
          >
            Läs
          </button>
        </form>
      </div>
    );
  }
}

export default Login;