SlideShare uma empresa Scribd logo
1 de 3
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
 
React js
React jsReact js
React js
 
React hooks
React hooksReact hooks
React hooks
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
React and redux
React and reduxReact and redux
React and redux
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Pluginkla2019 - React Presentation
Pluginkla2019 - React PresentationPluginkla2019 - React Presentation
Pluginkla2019 - React Presentation
 
React custom renderers
React custom renderersReact custom renderers
React custom renderers
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Asp dot-net core problems and fixes
Asp dot-net core problems and fixes Asp dot-net core problems and fixes
Asp dot-net core problems and fixes
 
React: JSX and Top Level API
React: JSX and Top Level APIReact: JSX and Top Level API
React: JSX and Top Level API
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorial
 
React render props
React render propsReact render props
React render props
 
Angular 2
Angular 2Angular 2
Angular 2
 
React JS part 1
React JS part 1React JS part 1
React JS part 1
 
React redux-redux-saga-rahil-memon
React redux-redux-saga-rahil-memonReact redux-redux-saga-rahil-memon
React redux-redux-saga-rahil-memon
 

Semelhante a React js t4 - components

Semelhante a React js t4 - components (20)

React JSX.pptx
React JSX.pptxReact JSX.pptx
React JSX.pptx
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
React js t2 - jsx
React js   t2 - jsxReact js   t2 - jsx
React js t2 - jsx
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16
 
React outbox
React outboxReact outbox
React outbox
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
 
Using react with meteor
Using react with meteorUsing react with meteor
Using react with meteor
 
Understanding React JSX_ A Beginner's Guide
Understanding React JSX_ A Beginner's GuideUnderstanding React JSX_ A Beginner's Guide
Understanding React JSX_ A Beginner's Guide
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
 
React redux
React reduxReact redux
React redux
 
Ways to Set Focus on an Input Field After Rendering in React.pptx
Ways to Set Focus on an Input Field After Rendering in React.pptxWays to Set Focus on an Input Field After Rendering in React.pptx
Ways to Set Focus on an Input Field After Rendering in React.pptx
 
Interview Questions On React JS.pptx
Interview Questions On React JS.pptxInterview Questions On React JS.pptx
Interview Questions On React JS.pptx
 
"How to... React" by Luca Perna
"How to... React" by Luca Perna"How to... React" by Luca Perna
"How to... React" by Luca Perna
 
Intro to React | DreamLab Academy
Intro to React | DreamLab AcademyIntro to React | DreamLab Academy
Intro to React | DreamLab Academy
 
3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
REACT pdf.docx
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
 

Mais de Jainul Musani

Mais de Jainul Musani (20)

ExpressJs Session01
ExpressJs Session01ExpressJs Session01
ExpressJs Session01
 
NodeJs Session03
NodeJs Session03NodeJs Session03
NodeJs Session03
 
NodeJs Session02
NodeJs Session02NodeJs Session02
NodeJs Session02
 
Nodejs Session01
Nodejs Session01Nodejs Session01
Nodejs Session01
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
 
Fundamentals of JDBC
Fundamentals of JDBCFundamentals of JDBC
Fundamentals of JDBC
 
Core Java Special
Core Java SpecialCore Java Special
Core Java Special
 
Core Java Special
Core Java SpecialCore Java Special
Core Java Special
 
Cassandra-vs-MongoDB
Cassandra-vs-MongoDBCassandra-vs-MongoDB
Cassandra-vs-MongoDB
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
MongoDB-SESSION02
MongoDB-SESSION02MongoDB-SESSION02
MongoDB-SESSION02
 
MongoDB-SESION01
MongoDB-SESION01MongoDB-SESION01
MongoDB-SESION01
 
4+1archi
4+1archi4+1archi
4+1archi
 
Python 1
Python 1Python 1
Python 1
 
eCertificate-JAVA-2
eCertificate-JAVA-2eCertificate-JAVA-2
eCertificate-JAVA-2
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
SAP for Beginners
SAP for BeginnersSAP for Beginners
SAP for Beginners
 
Difference WAMP and XAMPP
Difference WAMP and XAMPPDifference WAMP and XAMPP
Difference WAMP and XAMPP
 
Linux17 MySQL_installation
Linux17 MySQL_installationLinux17 MySQL_installation
Linux17 MySQL_installation
 
Linux16 RPM
Linux16 RPMLinux16 RPM
Linux16 RPM
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 

Último (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

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') );