DEV Community

Nguyen Hoang
Nguyen Hoang

Posted on

add item to array

const [items, setItems] = useState([]);
const [input, setInput] = useState("");

const handleAddItem = () => {
if (input.length > 0) {
setItems([...items, input]);
setInput('');
}
};

Top comments (0)