Skip to content

Instantly share code, notes, and snippets.

@unes
Created August 26, 2023 16:15
Show Gist options
  • Save unes/8367e6eddda05a91a6d605f8f434d5c7 to your computer and use it in GitHub Desktop.
Save unes/8367e6eddda05a91a6d605f8f434d5c7 to your computer and use it in GitHub Desktop.
React - Variable Attributes in JSX
// 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