03. Intro to React JS
03. Intro to React JS
03. Intro to React JS
Intro to React JS
Outline
● Javascript DOM
● Intro to ReactJs
● Component & props
● Class based component vs functional component
● Routing
What is DOM ?
The Document Object Model (DOM) in Javascript is a way to interact with and manipulate web pages. Think
of a web page as a document, like a book or a magazine. The DOM is like a tool that allows you to change,
read, and update the contents of that document (web page) using Javascript.
Key points:
● Document: The "D" in DOM stands for "Document," which is your web page. It includes everything
you see on a webpage - text, images, links, buttons, forms, and more.
● Object: The "O" in DOM stands for "Object." In programming, objects are like containers for data and
actions. The DOM represents your web page as a structured set of objects that you can manipulate.
● Model: The "M" in DOM stands for "Model." It's a way to represent the structure of your web page in a
logical and organized manner. This model is hierarchical, like a family tree, where elements (like
paragraphs, headings, or images) are related to one another.
Src : https://en.wikipedia.org/wiki/Document_Object_Model
DOM Manipulation with Javascript
DOM manipulation is the process of using Javascript
to interact with and change the content, structure,
and style of a web page represented by the DOM.
To modify the DOM (Document Object Model) in JavaScript, you can use various methods and properties
provided by the DOM API. Here are some common ways to modify the DOM:
Removing Elements:
● You can use the setAttribute method to set or modify attributes of an element.
● You can directly modify the style property to change the inline styles of an element.
HTML + Javascript DOM
Adding Event Listeners:
What is ReactJS?
Why React?
This method is considered better because of its rendering speed. Because only certain elements/components are
updated without having to reload the entire page by utilizing Virtual DOM. And this system is implemented in
modern javascript environments, especially React JS.
Virtual DOM
The Virtual DOM allows React to efficiently track and update only the
elements that have changed, minimizing the work required to keep the web
page up to date. This results in faster rendering and a smoother user
experience. Find out more here:
https://react.dev/
Virtual DOM vs Real DOM
Virtual DOM:
Real DOM:
References :
● https://react.dev/learn/start-a-new-react-pr
oject
● https://vitejs.dev/guide/
Code Structure
Src : https://react.dev/learn/writing-markup-with-jsx
Characteristics of JSX
● JSX is not mandatory to use there are other ways to achieve the same thing
but using JSX makes it easier to develop react application.
● JSX allows writing expression in { }. The expression can be any JS
expression or React variable.
● To insert a large block of HTML we have to write it in a parenthesis i.e, ().
● JSX produces react elements.
● JSX follows XML rule.
● After compilation, JSX expressions become regular JavaScript function
calls.
● JSX uses camelcase notation for naming HTML attributes. For example,
tabindex in HTML is used as tabIndex in JSX.
Components
● Class components make use of ES6 class and ● Sometimes referred to as “dumb” or
“stateless” components as they simply accept
extend the Component class in React.
data and display them in some form; that is
● Sometimes called “smart” or “stateful” they are mainly responsible for rendering UI.
components as they tend to implement logic ● React lifecycle methods (for example,
and state. componentDidMount) cannot be used in
● React lifecycle methods can be used inside functional components.
● There is no render method used in functional
class components (for example,
components.
componentDidMount). ● These are mainly responsible for UI and are
● You pass props down to class components typically presentational only (For example, a
and access them with this.props Button component).
● Functional components can accept and use
props.
Class Based Component VS Function Component
Props
Src : https://react.dev/learn/passing-props-to-a-component
Props
Add Styling
Install:
npm i styled-components
Src : https://styled-components.com/docs
Routing
Src : https://reactrouter.com/en/main/start/tutorial
React Router
● https://nicepage.com
● https://www.behance.net
● https://www.figma.com
Thank You!
Thank You!