LoginSignup
2
1

More than 5 years have passed since last update.

Firebase Auth + React のsign upだけ

Last updated at Posted at 2018-06-30

Firebaseメモ。reactでユーザー登録するだけ。

import React from 'react';
import ReactDOM from 'react-dom';
import firebase from "firebase";

// initialize firebase app
firebase.initializeApp({
  // apiKeyなど
});

// SignUp component
class SignUp extends React.Component {
  constructor(props) {
    super(props);
    this.state = { email: '', password: '' };
    this.handleSignUp = this.handleSignUp.bind(this);
  }
  handleSignUp() {
    const { email, password } = this.state;
    firebase.auth().createUserWithEmailAndPassword(email, password);
  }
  render() {
    const { email, password } = this.state;
    return (
      <div>
        <div>
          <label htmlFor="email">Email</label>
          <input id="email" value={email} type="text" onChange={ (e) => this.setState({ email: e.target.value }) } />
        </div>
        <div>
          <label htmlFor="password">password</label>
          <input id="password" value={password} type="password" onChange={ (e) => this.setState({ password: e.target.value }) } />
        </div>
        <button onClick={this.handleSignUp} >Sign up</button>
      </div>
    );
  }
};


ReactDOM.render(
  <SignUp />,
  document.getElementById('root'),
);
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1