skip to Main Content

Javascript – Weird behviour when trying to update an array in reactjs

import { useRef, useState } from "react"; import "./styles.css"; export default function App() { const [array, setArray] = useState(["apple", "mango", "strawberry"]); console.log("outside", array, Date.now()); function update(e) { const name = document.getElementById("name").value; const pos = Number(document.getElementById("pos").value); setArray((prev) => { console.log("prev ===>",…

VIEW QUESTION
Back To Top
Search