2026-08-17 14:18

Status:


IBM - DFAR - Module 1 - Introduction to React and Class Components

==Building Rich Front-End Applications with React and ES6

  • Introduction to Front-End Frameworks and React:
    • React is being widely adopted for building modern web applications, it a framework that is generally used to build front-end applications

    • Library- is a repository of pre-written code segments it provides reusable functions and routines so that way you do not need to code everything from scratch

    • Libraries generally focus on specific tasks or functionalities and offer flexibility for integration and use with your code

    • Examples include: jQuery, Lodash, D3.js, and React

    • A Framework is a comprehensive software development platform that provides a foundation and structure for the development of an entire application, unlike libraries which just give you good reusable code

    • Frameworks provide foundation and structure for application building

    • They address other more specific concerns such as handling user requests, managing data flow, and structuring overall architecture

    • Some examples include: AngularJS, Ember JS, Svelte, and Vue.js

    • Front-End Framework- these are frameworks that focus on the user-facing portion of the application, using things like HTML, CSS, and JS in order to create dynamic and interactive user interfaces, that communicate with the server behind the scenes

    • Some popular front-end frameworks: React, AngularJS, and Vue.js

    • React is an open source JavaScript Library that was developed by meta, the company that runs facebook and Instagram.

    • It facilitates the creation of interactive user interfaces

    • The prominent features of React Include:

      • Components
      • Declarative Syntax
      • Virtual DOM
      • One-way data binding
      • JavaScript XML (JSX)
      • Hook Employment
    • Pasted image 20260817145728.png

    • The component based architecture of react generally allows for the use of reusable UI Elements

    • So, a developer would create an independent component that would focus on a certain task for feature

    • These components can be coded individually in different files and then overall brought together to be used in either a single web page or in multiple web pages

    • React also provides easy navigation tools for where you are at, letting you easily switch between different websites

    • Declarative Syntax which it uses to update the UI behavior based on states in the code, allowing for things like dynamic updates to variables because a set of code or component is run every single time a key stroke would happen

    • This generally lets the people try and work on focusing on the application behavior and works to manage the underlying DOM

    • Virtual DOM- so basically it does not directly manipulate the current DOM, but instead creates a copy of a DOM virtually, and then updates this virtual DOM each time something is ran

    • By then doing this, it can compare the two and update the original DOM with the Virtual one if changes are noticed

    • This optimizes performance and improves speed while allowing for things like dynamic elements to actually exist

    • One-Way Data Binding which makes sure that data flows unidirectionally from a parent component to a child component, which simplifies data management and reduces bug from inconsistent state

    • Pasted image 20260817150544.png

    • JavaScript XML (JSX)- This is a javascript syntax extension that basically allows for XML like code inside of javascript This pretty much lets you use that whole return (HTML CODE) get up inside of your different component classes and is how you would set up your front end structure

    • Hook Employment- handle states and other react features seamlessly, which basically eliminates the need for class component based coding, and lets you simplify component logic, promote code reuse, and easily manage stateful behavior

  • Understand React Structure:
    • React Build Tools-

      • CRA Tool, which can be used with npx create-react-app <app-name> which install some unnecessary files and folder, which can lead to a larger file size, so generally there was need to have a different better tool
      • Vite Tool- used to create something using npm create vite@latest, and is is an improved development tool, you can use it with react, angular, or JavaScript. It is most optimal because it uses JavaScript modules to de-bloat only really the programs that you need
    • Creating a Project with Vite

      • Pasted image 20260817153941.png
      • write npm create vite@latest inside terminal of the directory you want your project to exist
      • You then generally pick from the list of frameworks in the terminal, generally react with arrow keys
      • You can then also select the JavaScript variant for your personal use case, or something else if you would like
      • This creates the folder and then you generally can move into it, and then install the vite environment dependencies, and then you run the local host using npm run dev
    • You can then go to the local host site and you will see the website that you have created on there, you will generally need to run this every single time you need to work or see the website

    • It does update automatically though so you can use it throughout the whole process

    • React Folder Structure

    • Pasted image 20260817155905.png

    • Pasted image 20260817160007.png

    • There will be a general project folder which is going to be the main things that holds all of the sub folders and also some of the things like the package.json and package-lock.json which is the things that npm uses to install the modules inside of the node_modules folder

    • You then also have a src folder which is the place where YOUR code actually lives, and is where you will do mostly all of the editing for your application.

    • It has a App. css, App. jsx, index. css, and main.jsx

    • Mainly, your would use the index. css as the place where you put all of the styles that are global, like your main body and what not. The main. jsx is sort of the index for your entire app and points over to the outer index.html which is mostly empty and something you should NOT edit.

    • The main way to get into the thing is App.jsx where you can place most of your app code and things like other indexes for your components

    • You can include <yourown.jsx> & <yourown.css> styles for different components like how I did for the obsidian portal in the Midas cloud homepage site

  • Introduction to ES6:
    • EcmaScript 6 (ES 6)- Ecma is a standards organization that creates a wide range of global information and communication technology standards. The script portion is basically the JavaScript equivalent of it adhering to the Ecma specification, which came out in 2015, with newer ones being named after the year they came out in

    • ES 6 had a major impact on the different aspects of the JavaScript programming language. The main changes are:

      • let
      • const
      • Arrow functions
      • Promise
      • Class
    • Pasted image 20260817184431.png

    • The var keyword is used to define a variable that has global scope within of the function it is created in, however let instead gives a variable only scope in it’s current block, allowing for less classes of redefining global vars

    • Equally, const is a var declaration that must be initialized with a value, and can never be changed after initialization

    • Pasted image 20260817184528.png

    • Arrow functions allow you to basically declare functions the same way that you might call variables, and using this syntax is a shorter and cleaner way to work with functions

    • The above hand is an example of how you can declare a variable as a function, and because of this a variable holding a function can be either var, let, & const

    • Pasted image 20260817184724.png

    • Arrow Functions- can be called the exact same way as a regular function would be sayHello(); and can also be passed in as a parameter into another function for a callback

    • Pasted image 20260817184847.png

    • Arrow functions also take parameters just like regular functions do, and are declared in the same way as well, just inside of the parenthesis. Generally, they can also return a data type or an object the same way a regular function would

    • -A function can be declared with an arrow like shown above, this puts it into a variable so it can be stored and what not. If the function as no arguments, you declare it with the (),

    • if it has one parameter, then you can just put the name of it with no parenthesis. If it has more than one parameter, then you have to use the parenthesis.

    • As for the curly braces, if it only has one line of code and does not return anything, then it does not need the curly braces.

    • If it does return something or is more than one line, then it needs them

    • Pasted image 20260817185423.png

    • Promise Object is an object that represents the completion of an asynchronous operation and it’s return value.

    • Whenever you invoke a promise operation like with the async keyword I assume, then the promise is in the pending state

    • After the operation executes successfully, the promise if fulfilled, and rejected if not

    • In the image above can be seen an example of a promise

    • It takes in two params, and then if the current time is even, it returns a success, if it is not, then it returns a reject

    • Pasted image 20260817185626.png

    • Pasted image 20260817185652.png

    • Classes- this basically made object-oriented programming actually something that could be done inside of JavaScript

    • They are basically just classes, but they are built on prototypes go see the IBM Introduction to HTML, CSS, & JavaScript playlist for more information on all of that

  • Introduction to JSX:
    • Javascript XML (JSX) this basically combines javascript with HTML, and makes it much easier to create conceptually pleasing applications because you do not need to abstract out the files as much
    • It looks similar to HTML but also supports JavaScript Expressions directly inside of it, which is VERY useful
    • It still uses the </> and HTML elements in order to create tags and a DOM, below is some sample JSX Code
    • Pasted image 20260817190000.png
    • This basically lets you set up an element as a variable that you can easily actually manipulate inside of your code, but inside of react this is not exactly how you would do it, you can instead write it just like you would HTML code, but inside of the return (); expression at the bottom of the component
    • Browsers DO NOT UNDERSTAND JSX and therefore, you need to use bable in order to transform your JSX components and items into JS objects
    • The JS engine then actually parses these objects, and you are able to render them and use them properly and what not
    • You can actually use the create-react-app to handle the compilation for you
    • Benefits of JSX
      • It is more accessible, those who do not know HTML or JS can generally more readily understand and modify the code because it is more sown together almost
      • People who use only HTML or only JS would have a better understanding of the other when the two get combined into one, letting them conceptualize better
      • You also get early error detection because you have to compile the objects, meaning you get to know if something goes wrong
      • Inline styles keep code simple which I mean I do suppose you can do
      • It boosts performace because it optimizes your code as it translates from JSX to JavaScript
      • It is also more secure (IDK ABOUT THAT ONE, REACT HAD A PRETTY BIG SCARE)
    • Below is JSX vs JavaScript
    • Pasted image 20260817190615.png
    • Pasted image 20260817190625.png
  • CRA versus Vite Tool:
    Create React App (CRA)

    CRA is a development tool introduced by the React team to help developers create React applications.

    This tool sets up a development environment with all the necessary configurations and dependencies preconfigured, allowing developers to focus on building their React components and applications.

    CRA provides a standard build toolchain based on Webpack, which includes features like module reloading, ES6+ syntax support, and production-ready builds.

    It’s a reliable and robust solution for starting React projects, especially for beginners who want to develop small to medium-sized applications.

    To create a React project with the CRA tool, you need to give the following command:

    npx create-react-app your-app-name

    Vite

    Evan You, the creator of Vue.js, created the Vite tool. It is designed to be a fast development build tool for JavaScript projects, including multiple JavaScript frameworks.

    Vite leverages modern ES module imports and native browser support for ES modules to provide extremely fast hot module replacement and server start times during development.Unlike CRA, which uses Webpack, Vite uses Rollup for bundling, resulting in faster build times and improved performance, especially for larger projects.

    Vite also supports various modern JavaScript features out of the box, such as TypeScript, JSX, and CSS preprocessors, without additional configuration.

    Vite’s speed and simplicity make it a compelling choice for developers looking for a more efficient development experience, particularly as projects grow in size and complexity.

    To create React project with Vite, you need to use the following command:

    npm create vite@latest

    The above command will present you with different frameworks and libraries. You need to select React to create a React project.

  • Lesson 1 Summary:

    Congratulations! You have completed this lesson. At this point in the course, you know that:

    • Libraries offer reusable code components, while frameworks provide a comprehensive structure for building applications.
    • React features include component-based architecture, declarative syntax, virtual DOM optimization, one-way data binding, JSX integration, and React Hooks employment.
    • You can create React projects using Create React App (CRA) and use Vite as an alternative tool. Vite optimizes web project development by leveraging modern browser capabilities.
    • New features introduced in JavaScript as a part of ES6 are let, const, arrow functions, promise, and class.
    • JSX is an extension to JavaScript that transforms HTML-like text found in JavaScript files into standard JavaScript objects.

==Introduction to Class Components

  • Introduction to Components:
    • What is a React Component?- basically, a component is a modular chunk of code, and are generally the building blocks of react applications and make the building portion of your applications much easier and reusable

    • You are able to basically set up each component and have it be reusable so that way you can use the same react element multiple times in different scenarios as they come up. Letting for easy reuse of code for visual website elements

    • A react component takes on an optional input, and returns a React object which is what actually gets rendered onto the screen

    • The react component renders pieces of the webpage and is able to react it’s own state whenever the user interacts with it, which this ability is coded inside of the given component that you want to have that reactablility (though outside components aka parent ones can I assume interact with them too)

    • A component has THREE general features: properties, events, and states

      • Properties- are used to store and pass data between different parent and child components
      • Events- manage the DOM as a result of the user’s interaction with the system
      • States- are used to update the UI by basically holding information, sort of similar to variables by they are specifically interned and kept by the React portion of the Program
    • Function Components

      • Class- you can use the JS ES 6 classes in order to create React Class Components which can also pass data from one class component to another class component, these would use the main react functions such as state, props, and life-cycle methods. They are generally more complex than functional components, especially after hooks were added, so you do not see these much too often anymore
      • Pasted image 20260817201507.png
      • Functional- these components are written basically like JavaScript functions, they can take in arguments and they return out JSX code, and are generally what you might see in something like the App.jsx portion of your code, where you have a given app function and it renders out your HTML code. Hooks enabled state with these functions
      • Higher Order- these (HOC) allow you to reuse component logic by letting you compose components together, through the use of passing in a given component into another one as an argument
  • Working with React Class Components: Props and Event Handling:
    • Class Component- is a javascript class that extends the React. Component class from the React Library
    • Class Components were the primary way of defining components inside of React before hooks were generally invented
    • They are used to encapsulate UI components and their behavior into reusable building blocks.
    • Generally, these class components are defined using the ES 6 class syntax for JS, and are able to manage state, handle life-cycle events, and define component methods
    • Pasted image 20260817202040.png
    • You first import react inside of the given file so that way you can use all of the features of the React Library/Framework
    • This is the old school way that things were done in react, where you would basically have a class object that would extend outward from the React main Component class.
    • It would then have a given function that would be called render() which would have a return statement where in which you would write JSX code that would define any element you wish to draw
    • The export default MyComponent; which exports the MyComponent class as the default export from this file, which allows other files in the project to basically import the given component class by using similar syntax to the way react was imported
    • Pasted image 20260817202333.png
    • State is basically the data that a given component would need in order to hold and process data, letting them render and respond to user interactions
    • Once again, in this older way of using class components, you would use state by having something like a constructor and then a this.state variable, which you would then be able to actually change and manage with another function and whatever data that was inputted
    • You basically start up with an empty state of pre-defined values and are then able to handle a change in the state by updating the inner state of the class
    • Pasted image 20260817202634.png
    • The render method then updates the inner class as well by managing the inner above defined class values, letting you understand what goes where because the HTML or really JSX code is able to actually interact with the above hand variables, meaning you can set things like inner attributes and update them as well from the class object inside of the HTML
    • Props in-class Component- basically, a prop sends data from a parent component to a child component, allowing them to easily communicate
    • This means that props from a parent and gotten by the child are read only and unchangeable
    • Generally, you can also pass methods and functions from components
    • Pasted image 20260817203007.png
    • Okay so, inside of the code in the above hand side, you have a main component called OrganizationDetails() and you also import the child component EmployeeDetails() as well
    • You have a local variable that is not in the state of the OrganizationDetails component, and is basically just holding a string designation for the employee.
    • Then, inside of the JSX, you have the ExployeeDetails component which is the prop value for that component and is declared with the above hand mentioned string
    • This gets passed to the EmployeeDetails component as an attribute
    • Pasted image 20260817203316.png
    • The child class of the employee is then able to actually get the data from the parent organization class because the employee designation prop is accessed from the employee_designation component
    • This is done in the line of code const {employee_designation} = this.props; which basically deconstructs the input that this component would get from the parent function and then internalizes it for easier use
    • Then inside of the JSX you can basically do whatever you want with the state while it already exists
    • Pasted image 20260817203601.png
    • Event Handling is responding to user interactions inside of React, such as clicks mouse overs, submitting a form, or other such things
    • Event handling is done in the given above hand code using the onClick() property of the button element inside of JSX, which takes in a pre-defined function as it’s argument, letting you basically define the behavior of the button inside of the given HTML code itself, or using the arrow function feature to put it somewhere else and just pass that function in
  • Introduction to States:
    • States in Class Components basically allow you to change data in an application

    • Inside of a class component, the state object can be used to track data from a user that they might input onto a screen

    • It generally includes key-value pairs that specify different types of data you would want to track inside of the application

    • React Class Components have a built in state object that you can basically use in order to pass data into, but you can also use the useState function for things like functional components inside of React which is the more modern approach

    • A change in the state object, re-renders the whole component

    • TWO Types of React State

      • Local State- presents only in a single component that needs it, such as hiding and showing information, this means that they CANNOT BE ACCESSED BY OTHER COMPONENTS
      • Shared State- this is state that can be shared by multiple components, such as an order application, and OTHER COMPONENTS CAN ACCESS IT
    • A class component state is just a plain old javascript object that is used by React to represent information about the component’s current situation

    • The heart of every react component is it’s state, because it is what determines how a component actually renders and behaves

    • It allows you to create dynamic and interactive components

    • States in Class Components- is an instance with properties that control the behavior of the component

    • YOU are the one to manage and preserve the state inside of the React Component

    • So in other words, you control the state of a component in an object that might change over the lifecycle of the component

    • Pasted image 20260817204757.png

    • Using the state allows you to track any changes that might have went down during a user interaction with the component

    • This includes things like buttons, forms, or timers and what not.

    • Therefore, for example, a simple application a simple application that would increment the counter when a user presses a button, the inner counter state would update to increase the overall count, and as the count changes the inner state, the component is re-rendered to display the updated counter

    • Props- short for “properties” and is used to pass data between two different components, these things that are passed are read only however, which means that they cannot be changed by the children component that receives them

    • Pasted image 20260817210346.png

    • Props behavior basically, store attribute values and work like HTML attributes

    • They behave like arguments from a function that you an pass between components

    • They are immutable and can not be modified

    • If a variable gets modified during a process in the parent components life cycle, then it would belong to that parent component (what?)

    • You can also use props to allow a child component to access a method of a parent component, managing the state in the parent component

    • Pasted image 20260817210417.png

  • Class Component Lifecycle:
    • React class components have lifecycles, meaning that they go over THREE phases during their given lifetime
    • During each phase, React provides life-cycle methods that you can access
    • Each the three main phases include mounting, updating, and unmounting
    • In the mounting phase, you instantiate the component class constructor and assign it with default state and whatever props and what not
    • In the update phase the states and props of a component end up changing due to user events and interactions, changes can also occur from the backend. When a change occurs, the entire component is re-rendered
    • In the unmounting phase the component basically just gets removed from the UI overall
    • The DOM and the Lifecycle that starts whenever a component is actually created and then mounted on top of the DOM
    • Once mounted, React updates the DOM due to changes that occur in the component, this is done using the virtual DOM which is discussed further up in these notes
    • The components then proceed to die whenever the component is removed from the DOM, meaning they no longer get rendered to the page
    • React automatically invokes these methods as it would need, but you as the developer can manipulate them to gain more control over component behavior
    • Pasted image 20260817212158.png
    • Mount Methods
      • componentWillMount() this is invoked prior to the execution of the first render function
      • render() actually renders the object to the screen I assume
      • componentDidMount() this is then invoked right after rendering has actually been completed after the first time
    • Pasted image 20260817212326.png
      Update Methods
      • getDerivedStateFromProps() which is called if you have an updated prop and want to reflect that in the component state
      • getsnapshotBeforeUpdate() this gives you access to the previous component state before it had actually updated
      • shouldComponentUpdate() which generally always returns true, and should only be made to return false if you do not want to component to update upon interaction
      • componentDidUpdate() this method allows you to create side affects like sending network requests, and other such things after a component is done updating
      • You also re-render the component
    • Pasted image 20260817212406.png
    • Unmount Methods
      • componentWillUnmount() this is called before the component is removed from the page, denoting the end of it’s lifecycle, and this performs proper clean up like cancelling network requests and other such things
  • Lesson 2 Summary:
    • handled independently. 
    • The three types of React components are functional, class, and high-order components.
    • A class component in React is a JavaScript class that extends the React Component class from the React library. 
    • Class components manage state, handle lifecycle events, and define component methods.
    • In React, props, or properties, send data from a parent component to a child component.
    • Event handling is the process of responding to user interactions, such as clicks, mouseovers, mouseouts, form submissions, and so on, within a React application.
    • State is a plain JavaScript object that React uses to represent information about the component’s current situation.
    • Any changes in the state data cause the re-rendering of the component to reflect the change.
    • Components can create and manage their data with states, whereas they receive data from outside with props.
    • The lifecycle of each React component encompasses three key phases: Mounting, updating, and unmounting.
    • In component lifecycle, components are created or mounted on the DOM, they grow by updating, and then die or are unmounted on the DOM.

==Cheat Sheet

JSX syntax and Class ComponentDescriptionCode Example
Vite toolThis tool is used to create React projects with the latest versionnpm create vite@latest
JSX syntax with fragmentsJsx allows to include multiple tags within single parent tag only. For this you can include empty tags also known as fragments <></>1. <>

2.

This is a heading tag



3. </>
JSX syntax with parent tagJsx allows to include multiple tags within single parent tag only. For this you can include tags like div tag1.


2.

This is a heading tag



3.
Class componentA class component extends the Component class with a render method1. import React, { Component } from ‘react’

2. export default class Extra extends Component {

3. render() {

4. return (

5. <>

6.

This is class component



7. </>

8. )

9. }

10. }
State management in class componentState can be managed using this.state within constructor of class component1. import React, { Component } from ‘react’

2. export default class Extra extends Component {

3. constructor(){

4. super();

5. this.state={

6. count:0

7. }

8. }

9. render() {

10. return (

11. <>

12.

This is paragraph



13. </>

14. )

15. }

16. }
Access data of state management within class componentData can be accessed by including variable name declared within {} and include variable name within these curly braces1. import React, { Component } from ‘react’

2. export default class Extra extends Component {

3. constructor(){

4. super();

5. this.state={

6. count:0

7. }

8. }

9. render() {

10. return (

11. <>

12.

the count is {this.state.count}



13. </>

14. )

15. }

16. }
Props in class componentProps can be sent from parent component as attribute along with child component1. import React, { Component } from ‘react’

2. import ChildComponent from ’./ChildComponent’

3. export default class App extends Component {

4. constructor(){

5. super()

6. this.state={

7. title:“Manager”

8. }

9. }

10. render() {

11. return (

12. <>

13.

14. </>

15. )

16. }

17. }
Access props within child class componentProps can be accessed easily within the child class component using this.props.variable_name1. import React, { Component } from ‘react’

2. export default class Extra extends Component {

3. constructor(props){

4. super();

5. this.state={

6. count:0

7. }

8. }

9. render() {

10. return (

11. <>

12.

The count value is {this.props.title}



13. </>

14. )

15. }

16. }
Event handling in class componentEvents such as click events are handled by defining a function before the render method1. import React, { Component } from ‘react’;

2. class MyComponent extends Component {

3. handleClick() {

4. alert(‘Button clicked!’);

5. }

6. render() {

7. return (

8.


9.

Event Handling in Class Component



10.

11.


12. );

13. }

14. }

15. export default MyComponent;

==Glossary

TermDefinition
App.jsxThe root component of the React application.
BabelA tool used to compile jsx code in the browser.
ClassA template or blueprint for creating objects.
constAllows you to declare constants whose values cannot be changed.
eslintrc.cjsA configuration file used by ESLint, which is a popular linting tool for JavaScript and the .cjs extension, indicates that it is a CommonJS module.
ECMAScript 6(ES6)A standards organization that creates a wide range of global information and communications technology standards. JavaScript adheres to Ecma’s specification ES6, which came out in 2015.
FrameworkA comprehensive software development platform that provides a foundation and structure for building entire applications.
Front-end frameworkA framework that focuses on building the user-facing side of web applications.
.gitignoreA file that specifies which files and directories should be ignored by Git version control.
HookA feature that allows developers to handle states and other React features seamlessly, eliminating the need for class-based coding.
Index.htmlA fundamental part of web development projects, serving as the entry point for web applications.
JavaScript XML (JSX)A JavaScript syntax extension enabling HTML-like code within JavaScript.
letAllows you to restrict the scope of variables within the block where they are declared.
main.jsxThe entry point for the React application.
Node modulesA directory that contains all the dependencies installed through npm or yarn.
package.jsonA file that contains metadata about the project and dependencies.
Public directoryA directory that contains static assets like HTML files, images, and fonts.
ReactAn open-source JavaScript library that facilitates the creation of dynamic and interactive user interfaces for web applications.
README.mdA file that provides information about the project, including setup instructions, usage guidelines, and project documentation.
src directoryA directory that contains the source code for the React application.
SubclassThe class that is inheriting another class.
SuperclassThe class being inherited by the subclass.
thisA reference to the current object.
varA variable that can be used or referred from anywhere in the code.
ViteA build tool that speeds up the building and development of web projects by making optimum use of how current browsers handle JavaScript modules.
vite.config.jsA file that contains configuration settings for the Vite build tool.

References