A stored total goes stale when the list changes.
Acceptance criteria
- 1.The total should follow the list.
A stored total goes stale when the list changes.
function App() { const [items, setItems] = React.useState(["a", "b", "c"]) const [total, setTotal] = React.useState(3) return ( <div> <p id="total">{total}</p> <button id="add" onClick={() => setItems([...items, "d"])}>add</button> </div> ) } const root = ReactDOM.createRoot(document.getElementById("root")) root.render(<App />)
Output ready when you are
Press Run to render your code, or Submit to validate your solution.