2. Agenda
• JavaScript Essentials
• Event loop
• React JSX
• Libraries for ClientSide Web
Applications
• React DOM
• Environmental Setup
• NPM commands
• Overview of webpack
• Babel
• React Component
• Limitations of JSX
3. JavaScript
Essentials
1. Variables:
• Use let, const or var to declare variables.
• let and const are block-scoped, while var is function-scoped.
2. Data Types:
• JavaScript has various data types, including numbers, strings, booleans,
arrays, objects, and more.
3. Operators:
• Arithmetic operators (+, -, *, /, %)
• Comparison operators (==, ===, !=, !==, >, <, >=, <=)
• Logical operators (&&, ||, !)
• Assignment operators (=, +=, -=, *=, /=)
4. Conditional Statements:
• if, else if, and else for decision-making.
• The switch statement for multiple branching.
4. JavaScript
Essentials
1. Loops:
• for, while, and do...while loops for repetitive tasks.
2. Functions:
• Define functions using the function keyword or arrow functions (()
=> {}).
• Functions can accept parameters and return values.
3. Arrays:
• Create and manipulate arrays to store lists of data.
• Use array methods like push, pop, shift, unshift, splice, and
forEach.
4. DOM Manipulation:
• JavaScript is commonly used to interact with the Document Object
Model (DOM) to modify web page content and structure.
• You can select and manipulate elements using methods like
getElementById, querySelector, and addEventListener.
5. JavaScript
Essentials
1. Events:
• JavaScript can handle various events such as clicks, keypresses, and
form submissions using event listeners.
2. Asynchronous Programming:
• JavaScript is single-threaded, but it supports asynchronous operations
using callbacks, promises, and async/await.
• Promises and async/await are used to handle asynchronous code more
cleanly.
3. Error Handling:
• Use try...catch blocks to handle errors gracefully.
4. JSON:
• JavaScript Object Notation (JSON) is a common format for data
exchange.
• Use JSON.parse to convert JSON data into JavaScript objects and
JSON.stringify to convert JavaScript objects into JSON.
6. Event Loop
The event loop is a crucial part of the runtime environment, especially in the context of asynchronous
programming. It's responsible for managing and executing tasks (events) in a non-blocking manner,
ensuring that your code remains responsive even when performing time-consuming operations.
• Call Stack: The call stack is where JavaScript keeps track of function calls. When a function is
called, it's added to the top of the stack, and when it returns, it's removed from the stack. The call
stack is synchronous and works in a last-in, first-out (LIFO) manner.
• Callback Queue (Task Queue): The callback queue is also known as the task queue. It stores
functions (callbacks) that are ready to be executed. These functions are usually added to the queue
after completing asynchronous operations, such as I/O, timers, or network requests.
• Event Loop: The event loop is a continuous process that constantly checks the call stack and the
callback queue. It's responsible for moving functions from the callback queue to the call stack,
effectively scheduling and executing asynchronous operations.
7. React
JSX
JSX (JavaScript XML) is a syntax extension for
JavaScript often used with React, a popular
JavaScript library for building user interfaces.
JSX allows you to write HTML-like code within
your JavaScript code, making it easier to
define the structure of your UI components.
JSX is not limited to React and can be used in
other JavaScript frameworks as well.
8. Libraries
When building a client-side web application with React, you can use various libraries and tools to
enhance your development process and add additional functionality to your project.
• State Management:
• Redux: A predictable state container for managing application state.
• Mobx: A simple and scalable state management library.
• Recoil: A state management library for managing and sharing the state of your React
components.
• Routing:
• React Router: A widely used library for handling client-side routing in React applications.
• Reach Router: A routing library for React that is accessible and designed with reachability in
mind.
9. Libraries
• UI Components and Styling:
• Material-UI: A popular library that provides pre-designed, customizable components
following the Material Design guidelines.
• Ant Design: A set of high-quality React components with a focus on enterprise applications.
• Styled-components: A library for writing CSS in your JavaScript code using tagged template
literals.
• HTTP Requests:
• Axios: A popular library for making HTTP requests from the browser.
• Fetch API: A built-in browser API for making HTTP requests, often used with libraries like
axios or as a standalone solution.
10. Libraries
• Form Handling:
• Formik: A library for building forms in React with ease.
• React Hook Form: A library for managing forms using React hooks.
• Authentication and Authorization:
• Firebase: A comprehensive platform that provides authentication, real-time database, cloud
functions, and more.
• Auth0: An authentication and authorization platform with various SDKs for React applications.
11. React
DOM
The term "React DOM" refers to the part of the React library
that is responsible for rendering your React components to
the actual Document Object Model (DOM) of a web page. It is
a specific package within the React ecosystem called "react-
dom".
import React from 'react';
import ReactDOM from 'react-dom';
const element = <h1>Hello, World!</h1>; ReactDOM.render(element,
document.getElementById('root'));
12. Overview
of
webpack
Webpack is a popular open-source JavaScript
module bundler that is commonly used in
modern web development. Its primary purpose
is to take various web assets, such as
JavaScript, CSS, and images, and bundle
them together into a format that is optimized for
efficient delivery to a web browser. Webpack is
highly configurable and extensible, making it a
versatile tool for managing and optimizing your
project's assets.
14. Babel
Babel is an open-source JavaScript
compiler that allows developers to write
code in the latest ECMAScript (ES)
standards (such as ES6/ES2015 and
beyond) and then transform or
"transpile" that code into a backward-
compatible version of JavaScript that
can run in older web browsers or
environments.
15. Install
Babel
Install Babel and necessary loaders and plugins:
1. npm install --save-dev babel-loader @babel/core
@babel/preset-env @babel/preset-react
Create a file .babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
16. React Component
Basic
In React, a component is a
fundamental building block that
encapsulates a piece of user
interface and its behavior. React
components can be reusable and
are used to create the UI of a web
application. There are two primary
types of components in React:
functional components and class
components.
18. Example
import React from 'react';
function HelloWorld() {
return <div>Hello, World!</div>;
}
export default HelloWorld;
19. Class Component
Class components are more
advanced and can hold their own
internal state, making them
suitable for more complex
interactions. They extend the
(React.Component) class and
provide additional features, such
as lifecycle methods. Class
components are sometimes
referred to as stateful
components.
20. Example
import React, { Component } from 'react';
class HelloWorld extends Component {
render() {
return <div>Hello, World!</div>;
}
}
export default HelloWorld;
21. Limitations of JSX
1. JSX requires compilation before running in the browser.
2. Complex logic and control structures can make JSX code verbose and
harder to read.
Important Points:
• Learning curve for newcomers.
• No direct HTML comments; use {/* ... */}.
• Self-closing tags should include a trailing slash.
• Use className for CSS classes.
• Wrapping elements in parentheses when multiple elements are returned.
• Potential naming conflicts with reserved words (e.g., class vs. className).
• Not enforcing accessibility; developers need to ensure accessibility
manually.
• JSX is primarily used with React for UI development.