SlideShare a Scribd company logo
ReactJs : Tutorial-04-Components in ReactJs
What are Components in React JS?
Components are like pure JavaScript functions that help make the code easy by splitting the
logic into reusable independent code.
Components as functions
test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
function Hello() {
return <h1>Hello, from RTDL Tutorial
s!</h1>;
}
const Hello_comp = <Hello />;
export default Hello_comp;
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Hello_comp from './test.jsx';
ReactDOM.render(
Hello_comp,
document.getElementById('root')
);
Class as Component
test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
class Hello extends React.Component {
render() {
return
<h1>
Hello, from RTDL Tutorials!
</h1>;
}
export default Hello;
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Hello from './test.jsx';
ReactDOM.render(
<Hello />,
document.getElementById('root')
);
ReactJs : Tutorial-04-Components in ReactJs
What are Props in ReactJS?
Props are properties to be used inside a component.
They act as global object or variables which can be used inside the Component.
Props to Function Component
test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
function Hello(props) {
return <h1>
{props.msg}
</h1>;
}
const Hello_comp = <Hello msg="Hello,RTD
L Tutorials!"/>;
export default Hello_comp;
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Hello_comp from './test.jsx';
ReactDOM.render(
Hello_comp,
document.getElementById('root')
);
Props to Class Component
test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
class Hello extends React.Component {
render() {
return <h1>{this.props.msg}</h1>;
}
}
export default Hello;
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Hello from './test.jsx';
ReactDOM.render(
<Hello msg ="Hello, RTDL Tutorials!"
/>,
document.getElementById('root')
);
ReactJs : Tutorial-04-Components in ReactJs

More Related Content

PDF
React js t5 - state
PDF
React js t6 -lifecycle
PDF
React js t1 - introduction
PDF
React js t3 - es6
PDF
React js t8 - inlinecss
PDF
React js t7 - forms-events
PDF
React js use contexts and useContext hook
PDF
Introduction to React Hooks
React js t5 - state
React js t6 -lifecycle
React js t1 - introduction
React js t3 - es6
React js t8 - inlinecss
React js t7 - forms-events
React js use contexts and useContext hook
Introduction to React Hooks

What's hot (20)

PPTX
React-JS Component Life-cycle Methods
PPTX
React js
PPTX
React hooks
PPTX
React - Start learning today
PPTX
Redux workshop
ODP
Introduction to ReactJS
PDF
React and redux
PPTX
React and Flux life cycle with JSX, React Router and Jest Unit Testing
PPTX
React js programming concept
PPTX
Pluginkla2019 - React Presentation
PDF
React custom renderers
PDF
Redux and context api with react native app introduction, use cases, implemen...
PDF
Workshop 20: ReactJS Part II Flux Pattern & Redux
PDF
Asp dot-net core problems and fixes
PDF
React: JSX and Top Level API
PDF
React native app with type script tutorial
PPTX
React render props
PPTX
Angular 2
PPTX
React JS part 1
PPTX
React redux-redux-saga-rahil-memon
React-JS Component Life-cycle Methods
React js
React hooks
React - Start learning today
Redux workshop
Introduction to ReactJS
React and redux
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React js programming concept
Pluginkla2019 - React Presentation
React custom renderers
Redux and context api with react native app introduction, use cases, implemen...
Workshop 20: ReactJS Part II Flux Pattern & Redux
Asp dot-net core problems and fixes
React: JSX and Top Level API
React native app with type script tutorial
React render props
Angular 2
React JS part 1
React redux-redux-saga-rahil-memon
Ad

Similar to React js t4 - components (20)

PPTX
React JSX.pptx
PDF
Quick start with React | DreamLab Academy #2
PDF
React js t2 - jsx
PPTX
How to create components in react js
PPTX
Getting Started with React v16
PPTX
React JS Lecture 10.pptx Our clg lecture
PPTX
React outbox
PPTX
ReactJS.pptx
PPTX
Using react with meteor
PDF
Understanding React JSX_ A Beginner's Guide
PDF
2018 05-16 Evolving Technologies: React, Babel & Webpack
PDF
React redux
PPTX
Ways to Set Focus on an Input Field After Rendering in React.pptx
PPTX
Interview Questions On React JS.pptx
PDF
"How to... React" by Luca Perna
PDF
Intro to React | DreamLab Academy
PDF
3 Simple Steps to follow to Create React JS Components
PPTX
react-slides.pptx
PPTX
What is component in reactjs
PPTX
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
React JSX.pptx
Quick start with React | DreamLab Academy #2
React js t2 - jsx
How to create components in react js
Getting Started with React v16
React JS Lecture 10.pptx Our clg lecture
React outbox
ReactJS.pptx
Using react with meteor
Understanding React JSX_ A Beginner's Guide
2018 05-16 Evolving Technologies: React, Babel & Webpack
React redux
Ways to Set Focus on an Input Field After Rendering in React.pptx
Interview Questions On React JS.pptx
"How to... React" by Luca Perna
Intro to React | DreamLab Academy
3 Simple Steps to follow to Create React JS Components
react-slides.pptx
What is component in reactjs
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
Ad

More from Jainul Musani (20)

PDF
Core Java Interface Concepts for BCA Studetns
PDF
Java Abstract and Final Class for BCA students
PDF
Java Collection Framework for BCA Students
PDF
Simple Calculator using JavaFx a part of Advance Java
PDF
JavaFx Introduction, Basic JavaFx Architecture
PDF
ASP.NET 2010, WebServices Full Example for BCA Students
PDF
Palindrome Programme in PHP for BCA students
PDF
Leap Year Program in PHP for BCA students
PDF
"PHP and MySQL CRUD Operations for Student Management System"
PDF
Python: The Versatile Programming Language - Introduction
PPTX
Python a Versatile Programming Language - Introduction
PPTX
ExpressJs Session01
PPTX
NodeJs Session03
PPTX
NodeJs Session02
PPTX
Nodejs Session01
PDF
Java exercise1
PPSX
Fundamentals of JDBC
PPT
Core Java Special
PDF
Core Java Special
PPTX
Cassandra-vs-MongoDB
Core Java Interface Concepts for BCA Studetns
Java Abstract and Final Class for BCA students
Java Collection Framework for BCA Students
Simple Calculator using JavaFx a part of Advance Java
JavaFx Introduction, Basic JavaFx Architecture
ASP.NET 2010, WebServices Full Example for BCA Students
Palindrome Programme in PHP for BCA students
Leap Year Program in PHP for BCA students
"PHP and MySQL CRUD Operations for Student Management System"
Python: The Versatile Programming Language - Introduction
Python a Versatile Programming Language - Introduction
ExpressJs Session01
NodeJs Session03
NodeJs Session02
Nodejs Session01
Java exercise1
Fundamentals of JDBC
Core Java Special
Core Java Special
Cassandra-vs-MongoDB

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PDF
Pre independence Education in Inndia.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Institutional Correction lecture only . . .
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Classroom Observation Tools for Teachers
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Sports Quiz easy sports quiz sports quiz
Pre independence Education in Inndia.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Institutional Correction lecture only . . .
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
TR - Agricultural Crops Production NC III.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Basic Mud Logging Guide for educational purpose
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Renaissance Architecture: A Journey from Faith to Humanism
Classroom Observation Tools for Teachers
O7-L3 Supply Chain Operations - ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra

React js t4 - components

  • 1. ReactJs : Tutorial-04-Components in ReactJs What are Components in React JS? Components are like pure JavaScript functions that help make the code easy by splitting the logic into reusable independent code. Components as functions test.jsx import React from 'react'; import ReactDOM from 'react-dom'; function Hello() { return <h1>Hello, from RTDL Tutorial s!</h1>; } const Hello_comp = <Hello />; export default Hello_comp; index.jsx import React from 'react'; import ReactDOM from 'react-dom'; import Hello_comp from './test.jsx'; ReactDOM.render( Hello_comp, document.getElementById('root') ); Class as Component test.jsx import React from 'react'; import ReactDOM from 'react-dom'; class Hello extends React.Component { render() { return <h1> Hello, from RTDL Tutorials! </h1>; } export default Hello; index.jsx import React from 'react'; import ReactDOM from 'react-dom'; import Hello from './test.jsx'; ReactDOM.render( <Hello />, document.getElementById('root') );
  • 2. ReactJs : Tutorial-04-Components in ReactJs What are Props in ReactJS? Props are properties to be used inside a component. They act as global object or variables which can be used inside the Component. Props to Function Component test.jsx import React from 'react'; import ReactDOM from 'react-dom'; function Hello(props) { return <h1> {props.msg} </h1>; } const Hello_comp = <Hello msg="Hello,RTD L Tutorials!"/>; export default Hello_comp; index.jsx import React from 'react'; import ReactDOM from 'react-dom'; import Hello_comp from './test.jsx'; ReactDOM.render( Hello_comp, document.getElementById('root') ); Props to Class Component test.jsx import React from 'react'; import ReactDOM from 'react-dom'; class Hello extends React.Component { render() { return <h1>{this.props.msg}</h1>; } } export default Hello; index.jsx import React from 'react'; import ReactDOM from 'react-dom'; import Hello from './test.jsx'; ReactDOM.render( <Hello msg ="Hello, RTDL Tutorials!" />, document.getElementById('root') );