title: ReactJS OnKeyPress to trigger a button press
body: <p>I'm very new to <strong>ReactJS</strong> and I'm just trying to do some small things to understand more.</p>
  
  <p>I was wondering if the <strong>OnKeyPress</strong> can trigger a button press. I've seen a few <em>similar</em> questions but what the <strong>OnKeyPress</strong> triggered was just a console.log or an alert. So I wasn't sure how to trigger the button press.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>class Form extends React.Component {
    onButtonPress = (e) =&gt; {
      // this is just an example of what happens when the button is pressed.
      this.setState({isClicked: true});
    }
  
    keyPress = (event) =&gt; {
      if (event.key == 'Enter'){
        // How would I trigger the button that is in the render? I have this so far.
        this.onButtonPress();
      }
    }
  
    render() {
      return (
        &lt;div&gt;
          &lt;div className="fieldForm"&gt;
            &lt;input
              value={name}
              type="name"
              onKeyPress={this.keyPress}
            /&gt;
          &lt;/div&gt;
          &lt;Button onClick={this.onButtonPress}&gt;Submit&lt;/Button&gt;
        &lt;/div&gt;
      )
    }
  }
  </code></pre>
  
  <p>Please note that I didn't include everything in here such as the constructor, props, or the state object attributes.</p>
  
  <p>The purpose of this is to make it look like the button has been clicked. When the button is clicked, it'll show a small loading sign on the button. I want the same thing to happen if I were to press enter (with the loading sign on the button, that's why I want the button pressed).</p>
  
  <p>Is this possible?</p>