Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can React be used without JSX?

jsx is used tactically in React and helps developers understand React components by viewing the code in more detail. Now the question is, is it possible to use other methods such as using simple functions or using other libraries such as preact or inferno in the react library?

With the searches that I did, I think that other libraries such as preact or inferno can be used in the React library. Is this conclusion correct?

like image 969
Amir Asgari Avatar asked Sep 02 '25 13:09

Amir Asgari


1 Answers

Yes, we can use react without jsx for that we need to use React.createElement() everywhere in code. So, anything you can do with JSX can also be done with just React.createElement().

you can do this because jsx is being converted into React.createElement() using Babel compiler

Example:

JSX :-

<div>Hello Jsx</div>

React.createElement :-

React.createElement('div', null, 'Hello');

like image 176
Boricha Nikhil Kumar Avatar answered Sep 05 '25 04:09

Boricha Nikhil Kumar