Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
What is the use of data-reactid attribute in HTML ?
Next article icon

What are the advantages of using JSX in ReactJS ?

Last Updated : 10 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

JavaScript XML or JSX is an extension of the JavaScript language syntax. The React library is an extension to write XML-like code for elements and components. JSX tags have a tag name, attributes, and children. 

Although JSX is not a necessity to write React applications, it is extremely beneficial as it makes React code simpler and elegant. 

Syntax:

{/* Using JSX*/}
<div className="App">GeeksforGeeks</div>;

// Without JSX
React.createElement(
"div",
{ className: "App" },
"GeeksforGeeks"
);

Advantages of using JSX in React JS :

  • JSX helps us keep our code simpler and elegant when writing large pieces of code.
  • According to the React docs, most people find it helpful as a visual aid when working with UI inside the JavaScript code.
  • JSX also allows React to show more useful error and warning messages.
  • If one is familiar with HTML, it is quite easy to use JSX when building React application
  • Faster than normal JavaScript as it performs optimizations while translating to regular JavaScript.

Steps to Create React Application:

Step 1: Create a React application using the following command:

npx create-react-app example

Step 2: After creating your project folder i.e. example, move to it using the following command:

cd example

Project Structure:

Example: This example implements two same components using one with JSX and other without JSX.

Javascript

// Filename - App.js
 
import React from "react";
import Jsx from "./Components/Jsx";
import Nojsx from "./Components/Nojsx";
 
export default function App() {
    return (
        <div className="App">
            <Jsx />
            <Nojsx />
        </div>
    );
}
                      
                       

Javascript

// Filename - Components/Nojsx.js
 
import React from "react";
 
const Nojsx = () => {
    return React.createElement(
        "div",
        { id: "Nojsx", className: "GfgClass" },
        React.createElement("h1", null, "Welcome to GFG")
    );
};
 
export default Nojsx;
                      
                       

Javascript

// Filename - Components/Jsx.js
 
import React from 'react'
 
const Jsx = () => {
    return (
        <div className ='GfgClass'>
        <h1>Welcome to GFG</h1>
        </div>
    )
}
 
export default Jsx
                      
                       

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Output



Next Article
What is the use of data-reactid attribute in HTML ?
author
ananya2204
Improve
Article Tags :
  • ReactJS
  • Web Technologies
  • React-Questions

Similar Reads

  • What are the advantages of React.js ?
    React.js is a popular JavaScript library used for building dynamic and interactive user interfaces. It has become a go-to tool for developers due to its efficient architecture, high performance, and ease of use. This article highlights the key advantages of using React.js for web development and exp
    5 min read
  • What are the advantages of using Redux with ReactJS ?
    Redux is a state management tool for JavaScript applications. It is more commonly used with ReactJS but is also compatible with many other frameworks such as Angular, Vue, Preact, as well as vanilla JavaScript. It is important to note that even though React and Redux are frequently used together, th
    3 min read
  • What are the features of ReactJS ?
    Created by Facebook, ReactJS is a JavaScript library designed for crafting dynamic and interactive applications, elevating UI/UX for web and mobile platforms. Operating as an open-source, component-based front-end library, React is dedicated to UI design and streamlines code debugging by employing a
    4 min read
  • Advantages of using Functional Components with React Hooks
    In the past, React mainly used class-based components as its building blocks. However, functional components, which are essentially JavaScript functions that receive props (inputs) and return JSX (rendered content), were limited in their capabilities. With React 16.8 and the introduction of hooks, f
    4 min read
  • What is the use of data-reactid attribute in HTML ?
    The data-reactid attribute is a custom attribute that react can easily identify its components within the DOM. Just like the HTML "classes" and "id" attributes, "data-reactid" helps in uniquely identifying the element. What is data-reactid?The data-reactid is an attribute that is used as a unique id
    2 min read
  • What is the use of React.createElement ?
    React.createElement is a fundamental method of React JS. The main use of React.createElement is the Creation of a React component. It is the JavaScript format for creating react components. Also, the JSX react component when transpired invokes this only method for creating the component. Syntax:Reac
    2 min read
  • Why is the use of Synthetic Events in ReactJS ?
    React uses Synthetic Events with the purpose to wrap native events of the browser. For various performance reasons, synthetic Events are wrapped and reused across multiple native events of the different browsers. ReactJS implements a synthetic events system because that brings consistency and high p
    2 min read
  • What are the benefits of using hooks in React-Redux?
    Have you ever wondered how users create amazing websites and apps? Well, in the world of programming, they have some cool tools, and today we're going to explore one of them called "Hooks" in the superhero team of React-Redux. Prerequisites:ReactReact-ReduxReact HooksJavaScriptWhat are Hooks?Hooks a
    2 min read
  • What are the limitations of React.js ?
    React.js is a widely used JavaScript library for building Interactive UI with reusable components, and it has proven to be powerful and flexible. It has so many simple and efficient features. We’ve known the major pros of using React, from its reusable components and high-performance capabilities to
    3 min read
  • Explain the scenario where using a PureComponent is advantageous.
    React PureComponent is a supercharged component that automatically checks for an update before rendering. It is ideal for components that heavily rely on props and state. It achieves this by comparing incoming facts with what it already holds, avoiding unnecessary renderings and thus saving consider
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences