Last active
May 20, 2020 03:38
-
-
Save taylorbryant/883da5e29fb56358c646364db9fb7051 to your computer and use it in GitHub Desktop.
Master details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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