Skip to content

Instantly share code, notes, and snippets.

@taylorbryant
Last active May 20, 2020 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylorbryant/883da5e29fb56358c646364db9fb7051 to your computer and use it in GitHub Desktop.
Save taylorbryant/883da5e29fb56358c646364db9fb7051 to your computer and use it in GitHub Desktop.
Master details
const PRODUCTS = [
{ id: 1, name: "Potato chips", description: "Deliciousness" },
{ id: 2, name: "Glue", description: "Do not smell" }
]
function Master(props) {
return PRODUCTS.map(product => (
<button onClick={() => props.onClickProduct(product)} key={product.id}>
{product.name}
</button>
)
}
function Details(props) {
return (
<div>
<h1>{props.product.name}</h1>
<p>{props.product.description}</p>
</div>
)
}
function Page() {
const [selectedProduct, setSelectedProduct] = useState({})
return (
<div>
<Master onClick={setSelectedProduct} />
<Details product={selectedProduct} />
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment