React Form Component onSubmit Handler Not Working

后端 未结 4 1352
不思量自难忘°
不思量自难忘° 2021-02-07 13:29

I have the following React component:

class Form extends React.Component {
  handleSubmit(e) {
    e.preventDefault();

           


        
4条回答
  •  长情又很酷
    2021-02-07 14:29

    One obvious piece of information: do not forget to include your button inside the

    . I got stuck for a while until I figured out I had put my submit button outside my form, like this:

      
        
                  
      
    

    hence the onSubmit event was not being called, and would never be.

提交回复
热议问题