I try to store it in local storage but it did not work for me. It give me a error when I click of save draft button.
import React, { useEffect, useState } from "react";
import "./App.css";
function App() {
const [text, setText] = useState("");
const [totalcharacters, setTotalCharacters] = useState(0);
const [totalword, setTotalWord] = useState(0);
const handleDraft = (text) => {
if (localStorage.setItem("text", JSON.stringify(text))) {
setText(localStorage.getItem("text"));
}
};
useEffect(() => {
setTotalCharacters(text.length);
localStorage.setItem("text", text);
function findTotal(text) {
text = text.replace(/(^\s*)|(\s*$)/gi, "");
text = text.replace(/[ ]{2,}/gi, " ");
text = text.replace(/\n /, "\n");
setTotalWord(text.split(" ").length);
}
findTotal(text);
handleDraft(text);
// setTotalWord(text.split(' ').length)
}, [text, totalword]);