import React, { useState } from "react";
import "./App.css";
const App = () => {
const [newtodo, useTodo] = useState("");
const [list, useList] = useState([]);
function data() {
useList((v) => [...v, newtodo]);
console.log(list);
}
return (
<div>
<h1>Todo</h1>
<input onChange={(e) => useTodo(e.target.value)} value={newtodo} />
<button onClick={() => data()}>Add</button>
</div>
);
};
export default App;
It is ReactJ code written in Vite. When I give input 'one' my output is [''] and then I enter 'two' my output is ['','one']. Does anybody know why this happens?