DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • React Server Components (RSC): The Future of React
  • Scrolling With Konva.js and React
  • Cross-Platform Mobile Application Development: Evaluating Flutter, React Native, HTML5, Xamarin, and Other Frameworks

Trending

  • Enforcing Architecture With ArchUnit in Java
  • Monolith: The Good, The Bad and The Ugly
  • Event-Driven Microservices: How Kafka and RabbitMQ Power Scalable Systems
  • How to Create a Successful API Ecosystem
  1. DZone
  2. Coding
  3. JavaScript
  4. 3 Main Pillars in ReactJS

3 Main Pillars in ReactJS

This article explains ReactJS and the three main pillars of ReactJS, which are component, state, and props.

By 
Muthuramalingam Duraipandi user avatar
Muthuramalingam Duraipandi
·
Mar. 10, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
6.2K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I am going to explain ReactJS and the three main pillars of ReactJS, which are component, state, and props.

ReactJS

ReactJS is an open-source front-end technology. It is a Javascript library for developing UI components. It is a single-page application, and we can use it as a multi-page application, also. Facebook introduced ReactJS. Javascript and other libraries are very slow for updating or loading DOM, but ReactJS is faster for updating and loading DOM. So ReactJS has good performance than other libraries. It is more flexible. ReactJs introduced Virtual DOM. For example, suppose we want to create an e-commerce application in general. In that case, we start by creating individual pages and multiple components like a dashboard page (button, link, text, image, etc.) and a home page(button, link, text). Still, by using React, we can create custom components for some of the widely used elements like buttons or Texts that can be made reusable in the entire application. To be more specific, the Text box has properties like length, size, validations, shades, and other properties, but to keep the end user interactive, we always use a particular style and stick to it. Hence customizing and reusing makes a lot of sense.

ReactJS Structure

Requirements

  • VS code
  • Nodejs v18.9.0

Three Pillars of ReactJS

  1. Component
  2. State
  3. Props

ReactJS Component

Components are like JavaScript functions. It is specific functionality for building a User Interface like buttons, text, containers, headers, footers, and Pages(Home, dashboard, help). Here ReactJS has two types of Components.

Component

  1. Function Component
  2. Class Component

1. Functional Component

A functional component is like a JavaScript function. It is a stateless component. It doesn't have a render method, and it doesn't have a Constructor. We can't use the ReactJS life cycle example componentDidMount() in functional components. It takes props and returns JSX. It will return the HTML code.

Functional Component

2. Class component

The class component is a simple JavaScript class, and it will create the render function, and the Class component will return the react element. It supports the react life cycle. A class component is stateful.

Class Component


Code Snippet

JavaScript
 
import React, { Component } from 'react'

export default class DoorComponent extends Component {

    constructor(props){

     super(props);

     this.state = {

        name:"Muthuramalingam"

    }

    }

    componentDidMount(){

        updateName();

    }



    updateName(){

        this.setState ({

            name:"Muthuramalingam Duraipandi"

        });

    }

  render() {

    return (

      <div>Hi Welcome to Door component {this.state.name}</div>

    )

  }


State

The state is used to build a React object.It contains information like name, age, address, organization information, etc. The state can add and modify data based on user action, and it will re-render the page as well. The state object is initialized into Constructor.Add and modify states we can use for this. setState(), and if we want to add and modify the previous state in a functional component, we can use setState();

setState()

For updating an object's data, we can use the example below.

For updating an object's data, we can use the example below.

In the functional component, by using hooks, we can set the state using the keyword useState();

Example

If we want to set a string.

JavaScript
 
const [name,setName] = useState("");


setName is used to assign a value to a variable's name, such as:

JavaScript
 
setName("Muthu");


Here we can set the number.

JavaScript
 
const [age,setAge] = useState(0);


setAge for assigning the data to the age variable.

JavaScript
 
setAge(25);


Now we can set Array.

JavaScript
 
const [userList,setUserList] = useState([]);


setUserList to assign the data to userList variable.

JavaScript
 
setUserList([{"name":"Muthu"},{"name":"Ram"}]);


Props

Props are objects that are sent from a parent component to a child component. These objects are actually sent via HTML tags. So we can say it is an HTML tag value, too. So, props, we can do read-only.

Props in ReactJS

Sent data from the parent component to the child component.

JavaScript
 
<receiverComponent news="Today Gold rate is increased" />


Code Snippet

JavaScript
 
import React from 'react'

import receiverComponent from './receiverComponent';

function ratioStationComponent() {

  return (

    <div>

        <receiverComponent news="Today Gold rate is increased" />

        </div>

  )

}

export default ratioStationComponent


Here we are receiving data from the parent component.

JavaScript
 
import React from 'react'

function receiverComponent(props) {

  return (

    <div><div>

        <p>Hi Welcome to receiver component</p>

        <p>Today News {props.news}</p>



        </div></div>

  )

}

export default receiverComponent


Conclusion

I hope you learned about ReactJS and its main three pillars of reactJS.Thank you for reading this article.

Data structure HTML Open source Visual Studio Code React (JavaScript library) SENT (protocol)

Opinions expressed by DZone contributors are their own.

Related

  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • React Server Components (RSC): The Future of React
  • Scrolling With Konva.js and React
  • Cross-Platform Mobile Application Development: Evaluating Flutter, React Native, HTML5, Xamarin, and Other Frameworks

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!