title: Draftjs how to save input data to LocalStorage without overwriting the previous data?
body: <p>I am using a draftjs rich text editor to save my text input to local storage. Right now, my program is able to take text input and when I click save, it saves the text input to my local storage. Code:</p>
  
  <pre><code>import React from "react";
  import { Editor, EditorState, convertToRaw } from "draft-js";
  
  class SaveData extends React.Component {
    constructor(props) {
      super(props);
      this.state = { editorState: EditorState.createEmpty() };
      this.onChange = (editorState) =&gt; this.setState({ editorState });
    }
  
    getContentAsRawJson() {
      const contentState = this.state.editorState.getCurrentContent();
      const raw = convertToRaw(contentState);
      return JSON.stringify(raw, null, 2);
    }
    saveContent() {
      const json = this.getContentAsRawJson();
      localStorage.setItem("savedContent", json);
    }
  
    render() {
      return (
        &lt;div&gt;
          &lt;Editor editorState={this.state.editorState} onChange={this.onChange} /&gt;
          &lt;button onClick={this.saveContent.bind(this)}&gt;Save Content&lt;/button&gt;
          &lt;pre&gt;{this.getContentAsRawJson}&lt;/pre&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default SaveData;
  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xJBFt.png" rel="nofollow noreferrer">The input from the text editor saved in local storage</a></p>
  
  <p>However, I need the saveContent() function to not overwrite the existing content that is already saved in my local storage.
  An example of what I want to achieve would look like:</p>
  
  <ul>
  <li>I put in some text in the text editor, click save,  the text is saved
  in my local storage.</li>
  <li>Then I add some new text in the text editor,    click save, the text
  is saved alongside my previous input without    overwriting it.</li>
  <li>Load both text inputs into the text editor.</li>
  </ul>
  
  <p>I believe I need to save the states to an array in the local storage, and whenever I press save, it would append the new data at the end of the array. But I'm lost as to how to achieve this. 
  Any help would be appreciated.</p>