import React, { Component } from 'react';
import style from './style';

export default class CommentForm extends Component {
  constructor(props, ...args) {
    super(props, ...args);
    this.state = { text: '' };
  }

  onChange(e) {
    const text = e.target.value;
    this.setState({ text });
  }

  handleKeyDown(e) {
    if (e.key === 'Enter' && !e.shiftKey) {
      e.preventDefault();
      this.onSubmit();
    }
  }

  onSubmit() {
    const { addComment } = this.props;
    const text = this.state.text.trim();
    if (!text || text === '') {
      return;
    }

    const processedText = text.replace(/\r?\n/g, '<br />');
    addComment(processedText);
    this.setState({ text: '' });
  }

  render() {
    const { text } = this.state;
    return (
      <div style={style.wrapper}>
        <textarea
          style={style.input}
          onChange={e => this.onChange(e)}
          onKeyDown={e => this.handleKeyDown(e)}
          placeholder="Add your comment..."
          value={text}
        >
        </textarea>
        <button
          style={style.submitButton}
          onClick={() => this.onSubmit()}
        >Submit
        </button>
      </div>
    );
  }
}

@@ -35,16 +35,64 @@
 react';%0A
+import Textarea from 'react-textarea-autosize';%0A
 import s
@@ -848,17 +848,17 @@
        %3C
-t
+T
 extarea%0A
@@ -1066,17 +1066,17 @@
       %3C/
-t
+T
 extarea%3E

use react-textarea-autosize instead of textarea input