HOME

TheInfoList



OR:

JSX (JavaScript Syntax Extension and occasionally referred as JavaScript
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable ...
) is a
React REACT or React may refer to: Science and technology *REACT (telescope), a telescope at Fenton Hill Observatory, New Mexico, US Computing * React (JavaScript library) , a JavaScript library for building user interfaces, from Facebook ** React Nati ...
extension to the
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
language syntax which provides a way to structure component rendering using syntax familiar to many developers. It is similar in appearance to
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaSc ...
.
React REACT or React may refer to: Science and technology *REACT (telescope), a telescope at Fenton Hill Observatory, New Mexico, US Computing * React (JavaScript library) , a JavaScript library for building user interfaces, from Facebook ** React Nati ...
components are typically written using JSX, although they do not have to be as components may also be written in pure JavaScript. JSX is created by Meta (formerly
Facebook Facebook is an online social media and social networking service owned by American company Meta Platforms. Founded in 2004 by Mark Zuckerberg with fellow Harvard College students and roommates Eduardo Saverin, Andrew McCollum, Dustin Mosk ...
). It is similar to another extension syntax created by Meta for
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group. ...
called XHP.


Markup

An example of JSX code: const App = () =>


Nested elements

Multiple elements on the same level need to be wrapped in a single React element such as the
element shown above, a fragment delineated by or in its shorthand form <>, or returned as an array.


Attributes

JSX provides a range of element attributes designed to mirror those provided by HTML. Custom attributes can also be passed to the component. All attributes will be received by the component as props.


JavaScript expressions

JavaScript expressions (but not
statements Statement or statements may refer to: Common uses *Statement (computer science), the smallest standalone element of an imperative programming language *Statement (logic), declarative sentence that is either true or false *Statement, a declarative ...
) can be used inside JSX with curly brackets :

The example above will render:

11


Conditional expressions

If–else statements cannot be used inside JSX but conditional expressions can be used instead. The example below will render as the string 'true' because i is equal to 1. const App = () => The above will render:

true

Functions and JSX can be used in conditionals: const App = () => The above will render:
Section 1(first)
Section 2
Section 3
Code written in JSX requires conversion with a tool such as Babel before it can be understood by web browsers. This processing is generally performed during a
software build In software development, a build is the process of converting source code files into standalone software artifact(s) that can be run on a computer, or the result of doing so. Functions Building software is an end-to-end process that involves m ...
process before the application is deployed.


See also

*
ECMAScript for XML ECMAScript for XML (E4X) is the standarprogramming language extension that adds native XML support to ECMAScript (which includes ActionScript, JavaScript, and JScript). The goal is to provide an alternative to DOM interfaces that uses a simpler syn ...


References


External links

* {{Official website, https://facebook.github.io/jsx/, Draft: JSX Specification 2014 software Facebook software JavaScript Open formats XML markup languages