```
class Blog extends React.Component {
  constructor(props) {
    super(props);
    this.interval = null;
    this.selectionStartIndex = null;
    this.selectionEndIndex = null;
  }

  componentWillMount() {
    this.interval = setInterval(() => {
      this.setSelectionIndexes(document.activeElement);
    }, 100);
  }

  componentWillUnmount() {
    clearInterval(this.interval);
  }

  setBlog = (blog, cb) =>
    this.setState({ blog }, () => {
      this.code.innerHTML = blog;
      cb && cb();
  });

  setSelectionIndexes = elem => {
    if (elem.tagName === 'TEXTAREA') {
      this.selectionStartIndex = elem.selectionStart;
      this.selectionEndIndex = elem.selectionEnd;
    }
  };
  render() {
    return (

      <TextArea
        value={blog}
        onChange={e => this.setBlog(e.target.value)}
        rows={8}
      />
    );
  }
}

```

I'm doing a markdown editor. In SO I found a question on how to get the selected values from a text area. As you can see in the method it uses setInterval to continually check if there is a selected text, but I'm some how frustrated to using this method to get the selected text in a text area. Is there a better way like an event to know when there is a selected text in a text area instead of polling?