Refactoring the code
The code we have now isn’t too hard to understand, but it has some room for improvement. Let’s quickly look at what we have got so far:
export function PizzaShopApp() {
const [cartItems, setCartItems] = useState<string[]>([]);
const addItem = (item: string) => {
setCartItems([...cartItems, item]);
}
return <>
<h1>The Code Oven</h1>
<div data-testid="menu-list">
<ol>
{pizzas.map((x) => <li>
{x}
<button onClick={() => addItem(x)}>Add</button>
</li>)}
</ol>
...