ReactJS: how to trigger form submit event from another event

后端 未结 2 723
难免孤独
难免孤独 2020-12-31 17:05

I\'ve two react events:

  1. Form submit event

    sendMessage: function(event){
        console.log(event);
        event.preventDefault();
    },
             
    
    
            
2条回答
  •  隐瞒了意图╮
    2020-12-31 17:24

    It's your component, so you don't need to worry about passing actual events around. You have some event handlers, and then you have the actual action.

    sendMessage: function(){
        console.log('message:', this.state.message);
    },
    handleFormSubmit: function(event){
        event.preventDefault();
        this.sendMessage();
    },
    handleTextareaKeypress: function(event){
        if (event.which == 13 && !event.shiftKey){
            this.sendMessage();
        }
    }
    

提交回复
热议问题