Lesson 1 of 11
Lesson Progress: 0%
The DOM, or Document Object Model, is the browser’s tree-like representation of a web page, where each element such as a heading, paragraph, or button becomes an object the browser can work with. JavaScript can read that structure, change text, add or remove elements, and respond to user actions by manipulating those objects directly. React does not usually edit the DOM one manual step at a time; instead, you describe what the UI should look like based on data and state. When that data changes, React figures out what parts of the page need updating and applies those changes to the real DOM for you. This makes interface code easier to organize because you focus on the desired result, while React handles the DOM updates behind the scenes.
Instructions
▼ ← Click the triangle to hide or reveal instructions.Hello function is a small React function that makes something show on the page.return React.createElement tells React to make an h1 heading with the words Hello, world!.render(Hello); is used so React can take that function and show its result on the screen.render(<Hello />);, which is shorter-looking.Render(<Hello />); is often easier for many people to read.Instructions
▼ ← Click the triangle to hide or reveal instructions.Bye function is a small React function that makes a heading for the page.() after Bye means this function does not need any input right now.return React.createElement tells React to create an h2 with the word Goodbye!.render(Bye); is needed so React will use the function and put the result onto the screen.render() is left out, the function exists, but nothing will appear on the page.Instructions
▼ ← Click the triangle to hide or reveal instructions.Message function is a small React function that shows one short message on the page.() means this function is not taking in any extra information right now.null means there are no extra settings being added to the paragraph.render() is omitted, the function is written, but the message will not appear on the screen.Instructions
▼ ← Click the triangle to hide or reveal instructions.() after Message means this function is not getting any input right now. is an empty set of extra settings for the paragraph., like a title or id, when you want to add more information. stays empty, changing nothing inside it will usually not change what you see on the page.render() is omitted, the function is written, but nothing will be shown on the screen.Instructions
▼ ← Click the triangle to hide or reveal instructions.{ title: "hello" } gives the paragraph extra information called a title.return sends the paragraph back so React can show it on the page.return is omitted, the paragraph is not sent back, so nothing will appear.{ } often changes extra details, but may not change the main text you see.title may change a small hover message, while the paragraph words stay the same.render() is omitted, React will not place the message onto the screen.React originally used both function components and class components, but class components were the main way to handle state and lifecycle features in earlier React apps. Class components are based on JavaScript classes, so they can feel heavier and require more code, such as extends React.Component, a render() method, and often more confusing use of this. One advantage of classes is that they made it possible to organize larger components in the early days of React, and many older codebases still use them. A drawback is that classes are often harder for beginners to read, harder to reuse cleanly, and easier to make mistakes in because of binding and this behavior. Function components started as the simpler option for display-only parts of the page, but they became much more powerful when React introduced Hooks, which let functions use state and other React features. Because of that change, function components are now the usual choice in modern React. Their main advantages are that they are shorter, easier to read, and usually easier to teach and maintain. Class components are still valid and important to recognize in older projects, but function components are generally preferred because they make React code feel simpler and more direct.
Instructions
▼ ← Click the triangle to hide or reveal instructions.class name, and inside it has a render() part.render() part tells React what should be shown on the screen.return sends back the heading so React can display it.Test Incomplete
function Hello() {
return React.createElement("h1", null, "Hello, world!");
}
render(Hello);function Bye() {
return React.createElement("h2", null, "Goodbye!");
}
render(Bye);function Message() {
return React.createElement("p", null, "This is a simple message.");
}
render(Message);function Message() {
return React.createElement("p", {}, "This is a simple message.")
}
render(Message);function Message() {
return React.createElement("p", { title: "hello" }, "This is a simple message.")
}
render(Message);class Hello extends React.Component {
render() {
return React.createElement("h1", null, "Hello, Again!")
}
}
render(React.createElement(Hello));