React is a JavaScript library for building web interfaces with JSX, which combines JavaScript and HTML-like syntax. Instead of manually creating elements, appending nodes, and attaching event listeners, describe interface output in terms of state and let React update the DOM. section 1.2.1 section 4.4
JSX compiles to JavaScript objects; the exact conversion depends on the compiler and its settings. React uses component elements to build a virtual DOM, then reconciles it with the previous version and updates the page DOM to match. section 4.4 section 1.2.1
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






