In the useState hook the setItems runs every time when the page is refreshed and sets the same items again. Can t=you help me with this, please.
useEffect(() => {
if (inputArr.length > 0) {
window.localStorage.setItem("inputArr", JSON.stringify(inputArr));
console.log("set", inputArr);
}
}, [inputArr]);
user27452169 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Here you are in a useEffect hook, not a useState hook.
That’s why setItem is triggered every page refreshing at first, and it will be triggered again if [inputArr] is changed.
CMGT_ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2