- It is a syntax extension to JavaScript.
- JSX is a
pseudo language
created by Facebook to allow usingHTML
insideJavascript
. - After compilation, JSX expressions become regular JavaScript function calls and evaluate to JavaScript objects.
- It is used .
- Due to JSX popularity, Starting from
React 17
, this conversion is delegated tobabel react plugin
. - React import code
import React from React
is not required from React 17. For more details visit here - Javascript function
React.createElement
can also be used to add HTML elements in components.
const App = () =>{ return React.createElement( 'div', {}, React.createElement( 'h1', {}, 'Hello World' ) ); }
- Due to JSX popularity, Starting from
- JSX should always return
single element
.<div>
tag or<>
[called as react fragment] can be used to wrap around and return multiple elements. - Since JSX is closer to JavaScript than to HTML, React DOM uses camelCase property naming convention instead of HTML attribute names. Example
onclick
event is used asonClick
const App = () =>{ return (<input type="button" onClick={hello}); }
- CSS
className
should be used instead ofclass
. - The
import
statement can be used to importjs
file andcss
files. The.js
file extension is optional but.css
extension is mandatory. - Every element in JSX should be closed
- Flower brackets
{}
can be used to execute Javascript code. {/* <jscode> */}
are used to comment JS code.