Clear and reset form input fields

前端 未结 12 1972
小蘑菇
小蘑菇 2020-11-28 22:36

I have a form containing various input fields and two buttons; one for submitting and one for cancelling.

12条回答
  •  甜味超标
    2020-11-28 23:12

    import React, { Component } from 'react'
    
    export default class Form extends Component {
      constructor(props) {
        super(props)
        this.formRef = React.createRef()
        this.state = {
          email: '',
          loading: false,
          eror: null
        }
      }
    
      reset = () => {
        this.formRef.current.reset()
      }
    
      render() {
        return (
          
    ) } }

提交回复
热议问题