I want to save on localStorage the text written in an input field

as I wrote in the title, I need to save on localStorage the text after it is written in TinyMCE by clicking on a button.
The problem is that it always saves in LocalStorage the placeholder(The “write something…” at line 6) when I press the button, I don’t know how to put the onChange in the input field.
I’m into coding since last month so there still a lot I need to learn, thanks a lot!!

class Form extends React.Component {

        render(){
           
            return <form method="post">
               <textarea id="mytextarea">Write something...</textarea>
               </form>;
        }
}

    ReactDOM.render(
        <Form/>,
        document.getElementById("root")
    );

    tinymce.init({
        selector: '#mytextarea'
    });
    
    class Button extends React.Component{

        save(){
            let mytextarea = document.getElementById("mytextarea").value;
            localStorage.setItem("myTextArea", mytextarea);
        }
        
        render(){
            return <button class="btn btn-success" id="button" onClick={this.save}>Save on 
         localStorage</button>;
        }
    }

    ReactDOM.render(
        <Button/>,
        document.getElementById("root2")
    );

Leave a Comment