React - Preventing Form Submission

前端 未结 11 901
一个人的身影
一个人的身影 2020-11-27 06:35

I\'ve been experimenting with React. In my experiement, I\'m using the Reactstrap framework.When I click a button, I\'ve noticed that the HTML form submits. Is there a way t

11条回答
  •  臣服心动
    2020-11-27 07:36

    import React, { Component } from 'react';
    
    export class Form extends Component {
      constructor(props) {
        super();
        this.state = {
          username: '',
        };
      }
      handleUsername = (event) => {
        this.setState({
          username: event.target.value,
        });
      };
    
      submited = (event) => {
        alert(`Username: ${this.state.username},`);
        event.preventDefault();
      };
      render() {
        return (
          
    ); } } export default Form;

提交回复
热议问题