Outputting Dynamic Content
Thus far, in all these examples, the content that was returned was static. It was content like <p>Hello World!</p>
—which of course is content that never changes. It will always output a paragraph that says, 'Hello World!'
.
At this point in the book, you don't yet have any tools to make the content more dynamic. To be precise, React requires that state concept (which will be covered in a later chapter) to change the content that is displayed (e.g. upon user input or some other event).
Nonetheless, since this chapter is about JSX, it is worth diving into the syntax for outputting dynamic content, even though it's not yet dynamic.
function App() { const userName = 'Max'; return <p>Hi, my name is {userName}!</p>; };
This example technically still produces static output since userName
never changes; but you can already see the syntax for outputting dynamic content...