- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 64字
- 2021-06-24 15:43:37
Props
JSX is very convenient when your DOM elements or React components have props. Using XML is pretty easy to set attributes on elements:
<img src="https://www.dev.education/images/logo.png" alt="DEV
Education" />
The equivalent in JavaScript would be as follows:
React.createElement("img", {
src: "https://www.dev.education/images/logo.png",
alt: "DEV Education"
});
This is far less readable, and even with only a couple of attributes it is harder to read without a bit of reasoning.