Your experience on this site will be improved by allowing cookies
React JSX
JavaScript XML or JSX is an XML or HTML like JavaScript syntax extension used by ReactJS. Processed into JavaScript calls of React Framework, it extends the ES6. This allows the HTML-like text to co-exist with JavaScript react code. This syntax is also used by the preprocessors with the purpose of converting the HTML-like syntax into standard JavaScript objects.
Nested Elements:
Nested Elements in JSX are needed to wrap with one container element.
Example: div as a container element.
App.JSX:
import React, { Component } from 'react'; class App extends Component{ render(){ return( HELLOWORLD |
Output:
HELLO WORLD |
Explanation: Here the container element div contains two nested elements within it.
JSX Attributes:
JSX uses camelcase naming convention for attributes and also allows the user to create his/her own custom attributes. To specify attribute values in JSX, there are two ways:
As String Literals: Here the values of the attributes are specified in double-quotes.
Example:
import React, { Component } from 'react'; class App extends Component{ render(){ return( Hello WorldHave a great day! |
Output:
Hello World Have a great day! |
As Expressions: Here, the values of attributes are specified as expressions using curly braces {}.
Example:
import React, { Component } from 'react'; class App extends Component{ render(){ return( {100+10} |
Output:
110 |
JSX Comments:
In JSX comments begin with /* and ends with */. The comment is then wrapped in curly braces {}.
Example:
{/* Comment in JSX */} |
JSX Styling:
Inline-styles are recommended for React.
Example:
import React, { Component } from 'react'; class App extends Component{ render(){ var X = { fontSize: 60, fontFamily: 'Courier', color: '#003300' } return ( Hello World |
Output:
Hello World |
JSX features:
0 comments