Created
August 26, 2023 16:15
-
-
Save unes/8367e6eddda05a91a6d605f8f434d5c7 to your computer and use it in GitHub Desktop.
React - Variable Attributes in JSX
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
// Use a variable to set the `height` and `width` attributes: | |
const sideLength = "200px"; | |
const panda = ( | |
<img | |
src="images/panda.jpg" | |
alt="panda" | |
height={sideLength} | |
width={sideLength} /> | |
); | |
const pics = { | |
panda: "http://bit.ly/1Tqltv5", | |
owl: "http://bit.ly/1XGtkM3", | |
owlCat: "http://bit.ly/1Upbczi" | |
}; | |
const panda = ( | |
<img | |
src={pics.panda} | |
alt="Lazy Panda" /> | |
); | |
const owl = ( | |
<img | |
src={pics.owl} | |
alt="Unimpressed Owl" /> | |
); | |
const owlCat = ( | |
<img | |
src={pics.owlCat} | |
alt="Ghastly Abomination" /> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment