0
What is JSX and how does it work in React?
subina kallyani
easy
0completed
0
Answer
JSX (JavaScript XML) is a syntax used in React that lets us write HTML-like code inside JavaScript.
It is mainly used to make React code simpler and more readable.
const element = <h1>Hello React</h1>;Even though it looks like HTML, JSX is not HTML.
Behind the scenes, JSX is converted into JavaScript using Babel:
React.createElement("h1", null, "Hello React");How JSX works (Simple Flow):
- Developer writes JSX
- Babel converts JSX into
React.createElement - React creates Virtual DOM elements
- Browser renders the UI
Important JSX Rules :
- JSX must return one parent element
- JavaScript expressions go inside
{ } - Use
classNameinstead ofclass - JSX prevents injection attacks by escaping values
Why JSX is preferred
- Improves readability
- Keeps UI and logic together
- Easier to maintain large applications
Click to Reveal Answer
Tap anywhere to see the solution
Revealed
Comments0