title: React js call to a function when enter key is pressed
body: <p>Here is a snippet from my react js app:</p>
  
  <pre><code>&lt;form className="rcw-sender" onKeyDown={(e)=&gt; e.keyCode == 13 ? {sendMessage}: ''} onSubmit={sendMessage}&gt;
    {this.state.active &amp;&amp; &lt;Container&gt;
      &lt;EmojiPicker /&gt;
    &lt;/Container&gt;}
    &lt;button className="rcw-send" onClick={activateEmoji}&gt;
      &lt;img src={emojibutton} className="rcw-send-icon" alt="send" /&gt;
    &lt;/button&gt;
    &lt;button className="rcw-send" onClick={activateMenu}&gt;
      &lt;img src={menubutton} className="rcw-send-icon" alt="send" /&gt;
    &lt;/button&gt;
  
    &lt;input type="text" className="rcw-new-message" name="message" placeholder={placeholder} disabled={disabledInput}
      autoFocus={autofocus} autoComplete="off" ref={this.input} /&gt;
    &lt;button type="submit" className="rcw-send"&gt;
      &lt;img src={send} className="rcw-send-icon" alt="send" /&gt;
    &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In my form <code>onSubmit={sendMessage}</code> is called when I press the submit button and this much works perfectly. But I want the same <code>sendMessage</code> to be invoked when I submit the form by pressing enter key. To do this I have this code <code>onKeyDown={(e)=&gt; e.keyCode == 13 ? {sendMessage}: ''}</code> from which I want the <code>sendMessage</code> method to be invoked on pressing the enter key but it doesn't seem to work. I want to do this because I have an emoji picker in my app and when I submit the form using enter key in that case the emoji picker show's up. So to fix this I want to invoke the <code>sendMessage</code> method when I press the enter key to submit the form. Submitting the form using the submit button doesn't toggle the state of the emoji picker. That's why as a quick fix to the problem I want to invoke <code>sendMessage</code> method when I press enter key. How do I do it?</p>