0 votes
in ReactJS by
What is JSX?

1 Answer

0 votes
by

JSX stands for JavaScript XML.

It allows us to write HTML inside JavaScript and place them in the DOM without using functions like appendChild( ) or createElement( ).

As stated in the official docs of React, JSX provides syntactic sugar for React.createElement( ) function.

**Note- We can create react applications without using JSX as well.

Let’s understand how JSX works:

Without using JSX, we would have to create an element by the following process:

const text = React.createElement('p', {}, 'This is a text');

const container = React.createElement('div','{}',text );

ReactDOM.render(container,rootElement);

Using JSX, the above code can be simplified:

const container = (

 <div>

   <p>This is a text</p>

 </div>

);

ReactDOM.render(container,rootElement);

As one can see in the code above, we are directly using HTML inside JavaScript.

Related questions

0 votes
asked Nov 8, 2023 in ReactJS by GeorgeBell
0 votes
asked Jan 30, 2021 in ReactJS by rajeshsharma
...