JS is a language describing logic and interaction. HTML is a language describing content, based on XML, which is meant to describe arbitrary data.
JSX, a shorthand for JS+XML, is these two languages put together into one. In JS, you can use numbers, strings, etc, but HTML code would cause errors. In JSX, HTML Code becomes a valid value that represents the actual HTML.
JSX is a combination of HTML and Javascript to put it simply, or as the official React site says: "a syntax extension of Javascript". It offers the functionality of writing Javascript expressions inside HTML elements which is then processed to create the UI.
e.g. this...
constnavBar=(<navclassName="bg-yellow"> Home </nav>);
Fo me JSX is a first selling pont of react (and nextjs). Because I can create any HTML releated stuffs at no time with simple js (ts) function, without need to know any template language syntax. I can use any js controll sequence for put together the view.
JSX also give good abstraction for view declaration.
// nextjs also can declare head elementsconstFooGameFrame=()=>{const[state,dispatch]=useSagaReducer(mainSaga,gameReducer,initialState);constarmy=getDispatchedActions(getActionsLookup(),dispatch);const{game,hero}=state;return(<sectionclassName='portal-root m-2'><MobilFrame><Head><title>Foo Game</title><metaname="viewport"content="initial-scale=1.0, width=device-width"/><linkrel="manifest"href="manifest.json"></link></Head>{game===GameMode.ROLL_CHARACTER&&<CreateHerostate={state}army={army}/>}{game===GameMode.ADVENTURE_ON_MAP&&<SingleAdventurestate={state}army={army}/>}{game===GameMode.BLOG&&<Blogname={hero?.name}avatar={hero?.avatar}/>}</MobilFrame>{game===GameMode.ADVENTURE_ON_MAP&&<CombatZonestate={state}army={army}/>}</section>);};
35+ years as a developer: Assembly, C, C++ & C# (in that order) with sidelines in ASP/VBScript, ASP.Net, JavaScript, Perl, VisualBasic, plus a few others.
Oldest comments (28)
An abomination
Very informative! π
π
lol
JSX is just fancy HTML (With some rules) that compiles to
pureJavaScript. So if you write something like this:It will compile to something like this:
So now you can generate HTML with JavaScript. This is the basic idea behind JSX.
Great example! π
πWelldone
JSX stands for JavaScript XML. It is mostly used with React to describe what the UI should look like.
Love this! π₯
JS is a language describing logic and interaction. HTML is a language describing content, based on XML, which is meant to describe arbitrary data.
JSX, a shorthand for JS+XML, is these two languages put together into one. In JS, you can use numbers, strings, etc, but HTML code would cause errors. In JSX, HTML Code becomes a valid value that represents the actual HTML.
JSX is a combination of HTML and Javascript to put it simply, or as the official React site says: "a syntax extension of Javascript". It offers the functionality of writing Javascript expressions inside HTML elements which is then processed to create the UI.
e.g. this...
... gets converted into:
Thank you for sharing!
Se denomina JSX a la combinaciΓ³n de HTML y JS para dar lugar a un cΓ³digo mucho mas compacto y elegante.
bien dicho hermano
Fo me JSX is a first selling pont of react (and nextjs). Because I can create any HTML releated stuffs at no time with simple js (ts) function, without need to know any template language syntax. I can use any js controll sequence for put together the view.
JSX also give good abstraction for view declaration.
Certainly!
JSX is a syntax candy created by React
JSX takes HTML, a simple straightforward way to describe formatted text, and made it verbose, complex and confusing.