Today in this article, I will discuss how to create react js components, but before we start
to create components, lets 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 dont need to create HTML tags on every page.
Before creating a component it is required to know that how you can install react-js.
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.
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 its not necessary to run all commands again you just run a single
command npm install then all packages are installed automatically.
selectBoxesOption is the name of your component. Your component name must start with
capital letter.
Now we are ready to create our React JS components and how to use in another le.
Now you can reuse this (LabelComponent) component. In any other 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.)
Contact Us
13 }
14 welcome(){
15 alert(Hello this is parent component);
16 }
17
18 return (
19 <div className="App">
20 <p>This is the parent component</p>
21 Hello <LabelComponent {...copanyDetail}/>
22 </div>
23 );
24 }
25 }
26 export default SelectBoxesOption;
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.
If you have any queries then ask your quires about react components in the comment
section.
Recent Posts
Categories
Mobile development
Our Partners
Web Development
Technologies
Node Js
Angular Js
Android
Ionic
MongoDB
Salesforce