Complex Objects in State
Using an Array as the State Value
import { useState } from "react";
const randInt = () => {
return Math.floor(Math.random() * 84);
};
const App = () => {
const [nums, setNums] = useState([4, 2]);
const addNum = () => {};
const removeOddNums = () => {};
return (
<div className="App">
<button onClick={addNum}>Add num</button>
<button onClick={removeOddNums}>Remove odd nums</button>
<ul>
{nums.map((n) => (
<li>{n}</li>
))}
</ul>
</div>
);
};
export default App;Using an Object as the State Value
Last updated