LoginSignup
0

More than 5 years have passed since last update.

react 전화번호 등록 기능 앱 만들기

Posted at
PhoneForm.js
import React, {Component} from 'react';

class PhoneForm extends Component {
  state = {
    name:'',
    phone:''
  }
  handleChange = (e) => {
    this.setState({
      //이벤트 입력값을 name 값을 통해서 가져온다
      [e.target.name]: e.target.value
    });
  }

  handleSubmit = (e) => {
    //페이지 리로딩 방지
    e.preventDefault();
    this.props.onCreate(this.state)

    this.setState({
      name:'',
      phone:''
    })
  }

  render() {
    return (
      <form>
        <input
          placeholder="name"
          value={this.state.name}
          onChange={this.handleChange}
          name="name"
        />

        <input
          placeholder="phone number"
          value= {this.state.phone}
          onChange= {this.handleChange}
          name="phone"
        />
        <div>{this.state.name}{this.state.phone}</div>
        <button type="submit">reg</button>
      </form>

      )
  }
}

export default PhoneForm;

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
0