// src/App.jsx import { useState } from "react"; function ColorSwatches({ onColorSelect }) { const colors = ["red", "green", "blue"]; return (
{colors.map((color) => ( ))}
); } function PreviewBox({ selectedColor }) { return (
); } function ColorPicker() { const [selectedColor, setSelectedColor] = useState(""); return (
); } function App() { return ; } export default App; /* Notes: - selectedColor lives in ColorPicker, the shared parent of both siblings — ColorSwatches and PreviewBox never talk to each other directly. - This combines two earlier patterns: .map() with a key (Chapter 6) for rendering the swatch buttons, and lifted state (this chapter) for keeping the preview in sync with whichever swatch was clicked. */