How React WorksN
How React WorksN
ReactDOM
Once we have created a React element, we’ll want to see
it in the browser.
ReactDOM contains the tools necessary to render React
elements in the browser.
ReactDOM is where we will find the render method.
ReactDOM.render(dish,document.getElementById("root"))
;
<body>
<div id="root">
<h1>Baked Salmon</h1>
</div>
</body>
React.createElement(
"ul",
null,
React.createElement("li", null, "2 lb salmon"),
React.createElement("li", null, "5 sprigs fresh rosemary"),
React.createElement("li", null, "2 tablespoons olive oil"),
React.createElement("li", null, "2 small lemons"),
React.createElement("li", null, "1 teaspoon kosher salt"),
React.createElement("li", null, "4 cloves of chopped garlic")
);
09/11/2024 Web Application Development 23
Every additional argument sent to the createElement
function is another child element.
const items = [
"2 lb salmon",
"5 sprigs fresh rosemary",
"2 tablespoons olive oil",
"2 small lemons",
"1 teaspoon kosher salt",
"4 cloves of chopped garlic"
];
React.createElement("ul",
{ className: "ingredients" },
items.map(ingredient => React.createElement("li", null,
ingredient))
);