0
0
Reactframework~10 mins

What is JSX in React - Visual Explanation

Choose your learning style9 modes available
Concept Flow - What is JSX
Write JSX code
React compiles JSX
JSX becomes React.createElement calls
React renders elements to DOM
User sees UI in browser
JSX is a syntax that looks like HTML but is transformed by React into JavaScript calls that create UI elements.
Execution Sample
React
const element = <h1>Hello, world!</h1>;
ReactDOM.render(element, document.getElementById('root'));
This code creates a JSX element and renders it inside the page element with id 'root'.
Execution Table
StepActionJSX CodeTransformed CodeResult
1Write JSX<h1>Hello, world!</h1>N/AJSX element created in code
2Compile JSX<h1>Hello, world!</h1>React.createElement('h1', null, 'Hello, world!')JSX transformed to React call
3Render elementReact.createElement('h1', null, 'Hello, world!')N/AReact renders <h1>Hello, world!</h1> in DOM
4Display UIN/AN/AUser sees 'Hello, world!' as heading on page
💡 Rendering completes and user sees the heading on the webpage.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
elementundefined<h1>Hello, world!</h1>React.createElement('h1', null, 'Hello, world!')Rendered in DOMDisplayed on page
Key Moments - 2 Insights
Why does JSX look like HTML but is not a string?
JSX looks like HTML but is actually JavaScript syntax that React compiles into function calls, as shown in step 2 of the execution_table.
What happens to JSX before it reaches the browser?
JSX is transformed by React's compiler into React.createElement calls before rendering, as seen in step 2 and 3 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what does the JSX <h1>Hello, world!</h1> become after compilation?
A'<h1>Hello, world!</h1>' string
Bdocument.createElement('h1')
CReact.createElement('h1', null, 'Hello, world!')
DA plain JavaScript object
💡 Hint
Check step 2 in the execution_table where JSX is compiled.
At which step does React actually put the element into the webpage DOM?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at the 'Render element' action in the execution_table.
If we change the JSX to <p>Hi!</p>, what changes in the execution_table?
AThe transformed code changes to React.createElement('p', null, 'Hi!')
BThe rendering step is skipped
CThe variable 'element' becomes undefined
DThe user sees 'Hello, world!' still
💡 Hint
Focus on how JSX transforms in step 2 of the execution_table.
Concept Snapshot
JSX is a syntax that looks like HTML inside JavaScript.
React compiles JSX into React.createElement calls.
These calls create React elements.
React renders these elements to the browser DOM.
JSX makes writing UI easier and clearer.
Full Transcript
JSX is a special syntax used in React that looks like HTML but is actually JavaScript. When you write JSX, React compiles it into calls to React.createElement. These calls create React elements that React uses to build the user interface. Finally, React renders these elements into the browser's DOM so the user can see the UI. This process lets developers write UI code that looks like HTML but works as JavaScript behind the scenes.