SlideShare a Scribd company logo
3 SIMPLE STEPS TO CREATE REACT JS
COMPONENTS
by Ashu | Jul 25, 2017 | Web Development | 0 comments
Today in this article, I will discuss how to create react js components, but before we start
to create components, let’s have an idea about what is components and why it is required.
The component is a small part of HTML tags. For example, input, label, select, etc.
It is required because after creating component we can use this component in many les.
we don’t need to create HTML tags on every page.
Before creating a component it is required to know that how you can install react-js.
Step 1: Install React.Js
> Create a folder in any drive,
> Open Command prompt.
> Enter commands and run.
• Npm install -g create-react-app
• Create-react-app my-app
• Cd my-app
U a
• Npm start
(Note: my-app is name of your application, your application run on browser)
Your Application Running Like This.
After the learning how to install react.js, it is important that where we can create our
component, so I am explaining the folder structure of react-js.
Step 2: Folder Structure
> Node_modules
> Public
• Favicon.ico
• Index.html
• Manifest.json
> Src
> Package.json
This is your folder structure. Your all packages are installed in node_modules which you
installed by command prompt for Exp: react.
In the src folder, you would include all your .js le.
The package.json le is your backup le of all your packages. When setup your application
on another system it’s not necessary to run all commands again you just run a single
command npm install then all packages are installed automatically.
Basic structure of your component
1 import React, { Component } from 'react';
selectBoxesOption is the name of your component. Your component name must start with
capital letter.
Import React, {Component} from ‘React’. It is necessary to import React in your
component. So, you should add this line in your every component.
Render()this function return a HTML.
Export default SelectBoxesOption all component are displayed on index.html so it is
compulsory to export your component.
Now we are ready to create our React JS components and how to use in another le.
Step 3: Component Creation
How to create a new component and uses in another
component:
Follow the following steps to create your another component.
> Create a folder in src ‘components’.
> Create a le in component folder ‘labelComponent.js’
> Write your code in labelComponent.js
> Import this component in your another component by,
2
3
4
5
6
7
8
9
10
11
class SelectBoxesOption extends Component {
    render() {
        return (
          <div className="App">
<p>This is the parent component</p>
             </div>
         );
         }
     }
     export default SelectBoxesOption;
1
2
3
4
5
6
7
8
9
10
11
import React, { Component } from 'react';
class LabelComponent extends Component{
    render() {
        return (
<div className=”demo”>
            <label className="label">Hello App</label>
</div>
        )
    }
}
export default LabelComponent;
1
2
3
4
import React, { Component } from 'react';
import LabelComponent from './components/LabelComponent';
class SelectBoxesOption extends Component {
render() {
Now you can reuse this (‘LabelComponent’) component. In any other component.
How to pass property from one component to another:
> Set a property in child component.
> Get this property in your child component by,
How to pass an object from one component to another.
> Create an object in your parent component and pass in child component by,
5
6
7
8
9
10
11
12
13
        return (
            <div className="App">
<p>This is the parent component</p>
<LabelComponent />
            </div>
        );
    }
}
export default SelectBoxesOption;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import React, { Component } from 'react';
import LabelComponent from './components/LabelComponent';
class SelectBoxesOption extends Component {
constructor(props){
    super(props);
}
render() {
        return (
            <div className="App">
   <p>This is the parent component</p>
   Hello <LabelComponent companyName={’Habilelabs’}/>
            </div>
        );
    }
}
export default SelectBoxesOption;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import React, { Component } from 'react';
class LabelComponent extends Component{
constructor(props){
    super(props);
}
render() {
        return (
<div className=”demo”>
            <label className="label">{this.props. companyName }</label>
</div>
        )
    }
}
export default LabelComponent;
1
2
import React, { Component } from 'react';
import LabelComponent from './components/LabelComponent';
> Get object in child component.
(NOTE: –In this code, we are using spread operator by this operator we can easily handle
an object, if you already have props as an object then we are using spread operator.)
How to pass a function from parent component to child
component using object.
> Create a function and pass this in object like,
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class SelectBoxesOption extends Component {
constructor(props){
    super(props);
}
render() {
const companyDetail = {
name: ‘habilelabs’,
address: ‘jaipur’
}
        return (
            <div className="App">
   <p>This is the parent component</p>
   Hello <LabelComponent {...copanyDetail}/>
            </div>
        );
    }
}
export default SelectBoxesOption;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import React, { Component } from 'react';
class LabelComponent extends Component{
constructor(props){
    super(props);
}
render() {
const {
name,
address
} = this.props;
        return (
<div className=”demo”>
            <label className="label">{name} In {address}</label>
</div>
        )
    }
}
export default LabelComponent;
1
2
3
4
5
6
7
8
9
10
import React, { Component } from 'react';
import LabelComponent from './components/LabelComponent';
class SelectBoxesOption extends Component {
constructor(props){
    super(props);
}
render() {
const companyDetail = {
name: ‘habilelabs’,
address: ‘jaipur’,
> Get object in child component.
Conclusion:
In this post, I guide you to create React JS components in your react application and I have
introduced 4 types of components. So, you can create new react application and use your
custom components in this application or you can add components in your existing
application with the help of this blog.
Learn how to install React Js : Automatic and Manual Installation 
If you have any queries then ask your quires about react components in the comment
section.
Hope you found it helpful, so don’t forget to share with friends.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
handleclick: this.welcome,
}
welcome(){
alert(“Hello this is parent component”);
          }
 
        return (
            <div className="App">
   <p>This is the parent component</p>
   Hello <LabelComponent {...copanyDetail}/>
            </div>
        );
    }
}
export default SelectBoxesOption;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import React, { Component } from 'react';
class LabelComponent extends Component{
constructor(props){
    super(props);
}
render() {
const {
name,
address,
handleclick
} = this.props;
        return (
<div className=”demo”>
            <label className="label">{name} In {address}</label>
  <button onClick={handleclick}>Show</button>
</div>
        )
    }
}
export default LabelComponent;
ContactUs
We're Online!
How may I help you today? 
Share on Facebook Share on Twitter Share on Google+
3 Simple Steps to Create React JS Components
Know 4 Types of Mistakes a Node JS Developer Makes
4 Basic Rest API Design Guidelines You should know
A Complete HTML and CSS Guidelines for Beginners
Steps to Create a Basic Application in Angular 2
What is Mini cation and It’s Bene ts
Recent Posts
Mobile development
Our Partners
Tech stack Migration
Web Development
Categories
Node Js
Angular Js
Android
Ionic
MongoDB
Salesforce
Technologies
Ad

More Related Content

What's hot (20)

React 16: new features and beyond
React 16: new features and beyondReact 16: new features and beyond
React 16: new features and beyond
Artjoker
 
React js t8 - inlinecss
React js   t8 - inlinecssReact js   t8 - inlinecss
React js t8 - inlinecss
Jainul Musani
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
Troy Miles
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
Troy Miles
 
React workshop
React workshopReact workshop
React workshop
Imran Sayed
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Knoldus Inc.
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
Commit University
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
React js t6 -lifecycle
React js   t6 -lifecycleReact js   t6 -lifecycle
React js t6 -lifecycle
Jainul Musani
 
React js t7 - forms-events
React js   t7 - forms-eventsReact js   t7 - forms-events
React js t7 - forms-events
Jainul Musani
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
Vlad Maniak
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
Gems Of Selenium
Gems Of SeleniumGems Of Selenium
Gems Of Selenium
Skills Matter
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
Mike Nakhimovich
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object pattern
Michael Palotas
 
Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
Neoito
 
React 16: new features and beyond
React 16: new features and beyondReact 16: new features and beyond
React 16: new features and beyond
Artjoker
 
React js t8 - inlinecss
React js   t8 - inlinecssReact js   t8 - inlinecss
React js t8 - inlinecss
Jainul Musani
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
Troy Miles
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
Troy Miles
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Knoldus Inc.
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
Commit University
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
React js t6 -lifecycle
React js   t6 -lifecycleReact js   t6 -lifecycle
React js t6 -lifecycle
Jainul Musani
 
React js t7 - forms-events
React js   t7 - forms-eventsReact js   t7 - forms-events
React js t7 - forms-events
Jainul Musani
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
Vlad Maniak
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
Mike Nakhimovich
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object pattern
Michael Palotas
 
Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
Neoito
 

Similar to 3 Simple Steps to follow to Create React JS Components (20)

What are the components in React?
What are the components in React?What are the components in React?
What are the components in React?
BOSC Tech Labs
 
Dyanaimcs of business and economics unit 2
Dyanaimcs of business and economics unit 2Dyanaimcs of business and economics unit 2
Dyanaimcs of business and economics unit 2
jpm071712
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
StephieJohn
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
SamyakShetty2
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
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
BOSC Tech Labs
 
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
BOSC Tech Labs
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
dhanushkacnd
 
MeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentMeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenment
Artur Szott
 
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
BOSC Tech Labs
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
Sergio Nakamura
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
REACT pdf.docx
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
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
Eswara Kumar Palakollu
 
React JS Lecture 10.pptx Our clg lecture
React JS Lecture 10.pptx Our clg lectureReact JS Lecture 10.pptx Our clg lecture
React JS Lecture 10.pptx Our clg lecture
ranjeet2000thakkar
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Pluginkla2019 - React Presentation
Pluginkla2019 - React PresentationPluginkla2019 - React Presentation
Pluginkla2019 - React Presentation
Angela Lehru
 
Unit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxUnit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
Ignacio Martín
 
What are the components in React?
What are the components in React?What are the components in React?
What are the components in React?
BOSC Tech Labs
 
Dyanaimcs of business and economics unit 2
Dyanaimcs of business and economics unit 2Dyanaimcs of business and economics unit 2
Dyanaimcs of business and economics unit 2
jpm071712
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
StephieJohn
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
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
BOSC Tech Labs
 
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
BOSC Tech Labs
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
dhanushkacnd
 
MeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentMeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenment
Artur Szott
 
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
BOSC Tech Labs
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
Sergio Nakamura
 
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
Eswara Kumar Palakollu
 
React JS Lecture 10.pptx Our clg lecture
React JS Lecture 10.pptx Our clg lectureReact JS Lecture 10.pptx Our clg lecture
React JS Lecture 10.pptx Our clg lecture
ranjeet2000thakkar
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Pluginkla2019 - React Presentation
Pluginkla2019 - React PresentationPluginkla2019 - React Presentation
Pluginkla2019 - React Presentation
Angela Lehru
 
Unit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxUnit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
Ignacio Martín
 
Ad

Recently uploaded (20)

machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
Ad

3 Simple Steps to follow to Create React JS Components

  • 1. 3 SIMPLE STEPS TO CREATE REACT JS COMPONENTS by Ashu | Jul 25, 2017 | Web Development | 0 comments Today in this article, I will discuss how to create react js components, but before we start to create components, let’s have an idea about what is components and why it is required. The component is a small part of HTML tags. For example, input, label, select, etc. It is required because after creating component we can use this component in many les. we don’t need to create HTML tags on every page. Before creating a component it is required to know that how you can install react-js. Step 1: Install React.Js > Create a folder in any drive, > Open Command prompt. > Enter commands and run. • Npm install -g create-react-app • Create-react-app my-app • Cd my-app U a
  • 2. • Npm start (Note: my-app is name of your application, your application run on browser) Your Application Running Like This. After the learning how to install react.js, it is important that where we can create our component, so I am explaining the folder structure of react-js. Step 2: Folder Structure > Node_modules > Public • Favicon.ico • Index.html • Manifest.json > Src > Package.json This is your folder structure. Your all packages are installed in node_modules which you installed by command prompt for Exp: react. In the src folder, you would include all your .js le. The package.json le is your backup le of all your packages. When setup your application on another system it’s not necessary to run all commands again you just run a single command npm install then all packages are installed automatically. Basic structure of your component 1 import React, { Component } from 'react';
  • 3. selectBoxesOption is the name of your component. Your component name must start with capital letter. Import React, {Component} from ‘React’. It is necessary to import React in your component. So, you should add this line in your every component. Render()this function return a HTML. Export default SelectBoxesOption all component are displayed on index.html so it is compulsory to export your component. Now we are ready to create our React JS components and how to use in another le. Step 3: Component Creation How to create a new component and uses in another component: Follow the following steps to create your another component. > Create a folder in src ‘components’. > Create a le in component folder ‘labelComponent.js’ > Write your code in labelComponent.js > Import this component in your another component by, 2 3 4 5 6 7 8 9 10 11 class SelectBoxesOption extends Component {     render() {         return (           <div className="App"> <p>This is the parent component</p>              </div>          );          }      }      export default SelectBoxesOption; 1 2 3 4 5 6 7 8 9 10 11 import React, { Component } from 'react'; class LabelComponent extends Component{     render() {         return ( <div className=”demo”>             <label className="label">Hello App</label> </div>         )     } } export default LabelComponent; 1 2 3 4 import React, { Component } from 'react'; import LabelComponent from './components/LabelComponent'; class SelectBoxesOption extends Component { render() {
  • 4. Now you can reuse this (‘LabelComponent’) component. In any other component. How to pass property from one component to another: > Set a property in child component. > Get this property in your child component by, How to pass an object from one component to another. > Create an object in your parent component and pass in child component by, 5 6 7 8 9 10 11 12 13         return (             <div className="App"> <p>This is the parent component</p> <LabelComponent />             </div>         );     } } export default SelectBoxesOption; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import React, { Component } from 'react'; import LabelComponent from './components/LabelComponent'; class SelectBoxesOption extends Component { constructor(props){     super(props); } render() {         return (             <div className="App">    <p>This is the parent component</p>    Hello <LabelComponent companyName={’Habilelabs’}/>             </div>         );     } } export default SelectBoxesOption; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import React, { Component } from 'react'; class LabelComponent extends Component{ constructor(props){     super(props); } render() {         return ( <div className=”demo”>             <label className="label">{this.props. companyName }</label> </div>         )     } } export default LabelComponent; 1 2 import React, { Component } from 'react'; import LabelComponent from './components/LabelComponent';
  • 5. > Get object in child component. (NOTE: –In this code, we are using spread operator by this operator we can easily handle an object, if you already have props as an object then we are using spread operator.) How to pass a function from parent component to child component using object. > Create a function and pass this in object like, 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class SelectBoxesOption extends Component { constructor(props){     super(props); } render() { const companyDetail = { name: ‘habilelabs’, address: ‘jaipur’ }         return (             <div className="App">    <p>This is the parent component</p>    Hello <LabelComponent {...copanyDetail}/>             </div>         );     } } export default SelectBoxesOption; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import React, { Component } from 'react'; class LabelComponent extends Component{ constructor(props){     super(props); } render() { const { name, address } = this.props;         return ( <div className=”demo”>             <label className="label">{name} In {address}</label> </div>         )     } } export default LabelComponent; 1 2 3 4 5 6 7 8 9 10 import React, { Component } from 'react'; import LabelComponent from './components/LabelComponent'; class SelectBoxesOption extends Component { constructor(props){     super(props); } render() { const companyDetail = { name: ‘habilelabs’, address: ‘jaipur’,
  • 6. > Get object in child component. Conclusion: In this post, I guide you to create React JS components in your react application and I have introduced 4 types of components. So, you can create new react application and use your custom components in this application or you can add components in your existing application with the help of this blog. Learn how to install React Js : Automatic and Manual Installation  If you have any queries then ask your quires about react components in the comment section. Hope you found it helpful, so don’t forget to share with friends. 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 handleclick: this.welcome, } welcome(){ alert(“Hello this is parent component”);           }           return (             <div className="App">    <p>This is the parent component</p>    Hello <LabelComponent {...copanyDetail}/>             </div>         );     } } export default SelectBoxesOption; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import React, { Component } from 'react'; class LabelComponent extends Component{ constructor(props){     super(props); } render() { const { name, address, handleclick } = this.props;         return ( <div className=”demo”>             <label className="label">{name} In {address}</label>   <button onClick={handleclick}>Show</button> </div>         )     } } export default LabelComponent; ContactUs We're Online! How may I help you today? 
  • 7. Share on Facebook Share on Twitter Share on Google+ 3 Simple Steps to Create React JS Components Know 4 Types of Mistakes a Node JS Developer Makes 4 Basic Rest API Design Guidelines You should know A Complete HTML and CSS Guidelines for Beginners Steps to Create a Basic Application in Angular 2 What is Mini cation and It’s Bene ts Recent Posts Mobile development Our Partners Tech stack Migration Web Development Categories Node Js Angular Js Android Ionic MongoDB Salesforce Technologies
  翻译: