SlideShare a Scribd company logo
2
Most read
ReactJs : Tutorial-02-JSX
What is JSX?
 JSX is an extension to javascript.
 It is a template script where you will have the power of using HTML and Javascript
together.
Here is a simple example of a JSX code.
const h1tag = "<h1>Hello, from RTDL Tutorials!</h1>";
Why we need JSX in React?
For a UI, we need Html, and each element in the DOM will have events to be handled, state
changes, etc.
In case of React, it allows us to make use of Html and javascript in the same file and take care
of the state changes in the DOM in an efficient manner.
Expressions in JSX
index.js
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello, from RTDL Tutorials!</h1>,
document.getElementById('root')
);
index.js
import React from 'react';
import ReactDOM from 'react-dom';
const display = "Hello, from RTDL Tutori
als!";
const h1tag = "<h1>{display}</h1>";
ReactDOM.render(
h1tag,
document.getElementById('root')
);
The Output will show the line as
ReactJs : Tutorial-02-JSX
What is the solution of this?
Create a text.jsx file and put the code in the file.
Import the test.jsx file in to index.js file and use it.
test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
const display = "Hello, to RTDL Tutorial
s";
const h1tag =<h1>{display}</h1>;
export default h1tag;
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import h1tag from './test.jsx';
ReactDOM.render(
h1tag,
document.getElementById('root')
);
Check the same in the browser: http://www.localhost:3000/index.html
Difference between js and jsx files
ReactJS - .JS vs .JSX
There is none when it comes to file extensions. Your bundler/transpiler/whatever takes care of
resolving what type of file contents there is.
There are however some other considerations when deciding what to put into a .js or a .jsx file
type. Since JSX isn't standard JavaScript one could argue that anything that is not "plain"
JavaScript should go into its own extensions ie., .jsx for JSX and .ts for TypeScript for example.

More Related Content

What's hot (20)

ODP
Introduction to ReactJS
Knoldus Inc.
 
PDF
React
중운 박
 
PDF
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
PDF
ReactJS presentation
Thanh Tuong
 
PPTX
React JS: A Secret Preview
valuebound
 
PDF
Introduction to Redux
Ignacio Martín
 
PDF
React JS - Introduction
Sergey Romaneko
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
React js
Oswald Campesato
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPTX
React hooks
Ramy ElBasyouni
 
PPTX
React workshop
Imran Sayed
 
PPTX
Introduction to React JS for beginners | Namespace IT
namespaceit
 
PPTX
ReactJs
Sahana Banerjee
 
PPTX
React with Redux
Stanimir Todorov
 
PDF
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
PDF
Understanding react hooks
Samundra khatri
 
PPTX
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
PDF
An introduction to React.js
Emanuele DelBono
 
Introduction to ReactJS
Knoldus Inc.
 
React
중운 박
 
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
ReactJS presentation
Thanh Tuong
 
React JS: A Secret Preview
valuebound
 
Introduction to Redux
Ignacio Martín
 
React JS - Introduction
Sergey Romaneko
 
[Final] ReactJS presentation
洪 鹏发
 
Introduction to React JS for beginners
Varun Raj
 
React hooks
Ramy ElBasyouni
 
React workshop
Imran Sayed
 
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React with Redux
Stanimir Todorov
 
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Understanding react hooks
Samundra khatri
 
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
An introduction to React.js
Emanuele DelBono
 

Similar to React js t2 - jsx (20)

PDF
Understanding React JSX_ A Beginner's Guide
Elightwalk Technology PVT. LTD.
 
PPTX
React JSX.pptx
avinashB60
 
PDF
Learn react by Etietop Demas
Etietop Demas
 
PPTX
ReactJS.pptx
SamyakShetty2
 
PDF
30 days-of-react-ebook-fullstackio
imdurgesh
 
PDF
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
PPTX
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
Ayes Chinmay
 
PDF
Reactjs workshop
Pankaj Bhageria
 
PPTX
slides.pptx
HafidzIhzaPratama
 
PPTX
slides.pptx
HarshitJain302462
 
PDF
Why I Love JSX!
Jay Phelps
 
PPTX
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
PPTX
From JSX to Deployment: Mastering the React Workflow for Scalable Front-End D...
sriniravir05
 
PDF
learning react
Eueung Mulyana
 
PDF
FRONTEND BOOTCAMP 3.pdf
Ehtesham46
 
PPTX
React js
Alireza Akbari
 
PPTX
Introduction to React native
Dhaval Barot
 
PPTX
React JS part 1
Diluka Wittahachchige
 
PDF
Stay with React.js in 2020
Jerry Liao
 
Understanding React JSX_ A Beginner's Guide
Elightwalk Technology PVT. LTD.
 
React JSX.pptx
avinashB60
 
Learn react by Etietop Demas
Etietop Demas
 
ReactJS.pptx
SamyakShetty2
 
30 days-of-react-ebook-fullstackio
imdurgesh
 
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
Ayes Chinmay
 
Reactjs workshop
Pankaj Bhageria
 
slides.pptx
HafidzIhzaPratama
 
slides.pptx
HarshitJain302462
 
Why I Love JSX!
Jay Phelps
 
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
From JSX to Deployment: Mastering the React Workflow for Scalable Front-End D...
sriniravir05
 
learning react
Eueung Mulyana
 
FRONTEND BOOTCAMP 3.pdf
Ehtesham46
 
React js
Alireza Akbari
 
Introduction to React native
Dhaval Barot
 
React JS part 1
Diluka Wittahachchige
 
Stay with React.js in 2020
Jerry Liao
 
Ad

More from Jainul Musani (20)

PDF
Core Java Interface Concepts for BCA Studetns
Jainul Musani
 
PDF
Java Abstract and Final Class for BCA students
Jainul Musani
 
PDF
Java Collection Framework for BCA Students
Jainul Musani
 
PDF
Simple Calculator using JavaFx a part of Advance Java
Jainul Musani
 
PDF
JavaFx Introduction, Basic JavaFx Architecture
Jainul Musani
 
PDF
ASP.NET 2010, WebServices Full Example for BCA Students
Jainul Musani
 
PDF
Palindrome Programme in PHP for BCA students
Jainul Musani
 
PDF
Leap Year Program in PHP for BCA students
Jainul Musani
 
PDF
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
PDF
Python: The Versatile Programming Language - Introduction
Jainul Musani
 
PPTX
Python a Versatile Programming Language - Introduction
Jainul Musani
 
PDF
React js t8 - inlinecss
Jainul Musani
 
PDF
React js t7 - forms-events
Jainul Musani
 
PDF
React js t6 -lifecycle
Jainul Musani
 
PDF
React js t5 - state
Jainul Musani
 
PDF
React js t4 - components
Jainul Musani
 
PDF
React js t3 - es6
Jainul Musani
 
PDF
React js t1 - introduction
Jainul Musani
 
PPTX
ExpressJs Session01
Jainul Musani
 
PPTX
NodeJs Session03
Jainul Musani
 
Core Java Interface Concepts for BCA Studetns
Jainul Musani
 
Java Abstract and Final Class for BCA students
Jainul Musani
 
Java Collection Framework for BCA Students
Jainul Musani
 
Simple Calculator using JavaFx a part of Advance Java
Jainul Musani
 
JavaFx Introduction, Basic JavaFx Architecture
Jainul Musani
 
ASP.NET 2010, WebServices Full Example for BCA Students
Jainul Musani
 
Palindrome Programme in PHP for BCA students
Jainul Musani
 
Leap Year Program in PHP for BCA students
Jainul Musani
 
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
Python: The Versatile Programming Language - Introduction
Jainul Musani
 
Python a Versatile Programming Language - Introduction
Jainul Musani
 
React js t8 - inlinecss
Jainul Musani
 
React js t7 - forms-events
Jainul Musani
 
React js t6 -lifecycle
Jainul Musani
 
React js t5 - state
Jainul Musani
 
React js t4 - components
Jainul Musani
 
React js t3 - es6
Jainul Musani
 
React js t1 - introduction
Jainul Musani
 
ExpressJs Session01
Jainul Musani
 
NodeJs Session03
Jainul Musani
 
Ad

Recently uploaded (20)

PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Introduction presentation of the patentbutler tool
MIPLM
 
Controller Request and Response in Odoo18
Celine George
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
epi editorial commitee meeting presentation
MIPLM
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
infertility, types,causes, impact, and management
Ritu480198
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Introduction to Indian Writing in English
Trushali Dodiya
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 

React js t2 - jsx

  • 1. ReactJs : Tutorial-02-JSX What is JSX?  JSX is an extension to javascript.  It is a template script where you will have the power of using HTML and Javascript together. Here is a simple example of a JSX code. const h1tag = "<h1>Hello, from RTDL Tutorials!</h1>"; Why we need JSX in React? For a UI, we need Html, and each element in the DOM will have events to be handled, state changes, etc. In case of React, it allows us to make use of Html and javascript in the same file and take care of the state changes in the DOM in an efficient manner. Expressions in JSX index.js import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <h1>Hello, from RTDL Tutorials!</h1>, document.getElementById('root') ); index.js import React from 'react'; import ReactDOM from 'react-dom'; const display = "Hello, from RTDL Tutori als!"; const h1tag = "<h1>{display}</h1>"; ReactDOM.render( h1tag, document.getElementById('root') ); The Output will show the line as
  • 2. ReactJs : Tutorial-02-JSX What is the solution of this? Create a text.jsx file and put the code in the file. Import the test.jsx file in to index.js file and use it. test.jsx import React from 'react'; import ReactDOM from 'react-dom'; const display = "Hello, to RTDL Tutorial s"; const h1tag =<h1>{display}</h1>; export default h1tag; Index.js import React from 'react'; import ReactDOM from 'react-dom'; import h1tag from './test.jsx'; ReactDOM.render( h1tag, document.getElementById('root') ); Check the same in the browser: http://www.localhost:3000/index.html Difference between js and jsx files ReactJS - .JS vs .JSX There is none when it comes to file extensions. Your bundler/transpiler/whatever takes care of resolving what type of file contents there is. There are however some other considerations when deciding what to put into a .js or a .jsx file type. Since JSX isn't standard JavaScript one could argue that anything that is not "plain" JavaScript should go into its own extensions ie., .jsx for JSX and .ts for TypeScript for example.