JSX lets JavaScript and HTML-like markup live together. It treats markup as a value: `const link = <a href="https://manning.com">Manning</a>;` can compile to a runtime call that creates an object. The exact output depends on the compiler and its settings. section 4.4
In React, components can return JSX based on their state. React handles the DOM updates, using a virtual DOM and reconciliation to compare element trees and update the page. This replaces direct DOM operations such as creating elements, appending children, and registering event listeners. section 4.4 section 4.5
Listing 4.3 An event list component in React
import React, { useState } from "react";
export default function EventList() { # A
const [events, setEvents] = useState(["Initial event"]); # B
return (
<ul id="event-list">
{events.map((str) => ( # C
<li>{str}</li> # C
))} # C
<li>
<input # D
onKeyDown={(evt) => { # D
setEvents( # D
events.concat(`Event "keydown" fired with key = # D
"${evt.key}"`), # D
); # D
}} # D
/> # D
</li>
</ul>
);
}
This event-list component maps state into list items and updates that state when a key is pressed. section 4.4








