Chapter 3 React
Chapter 3 React
➢ React VS Angular
➢ Virtual DOM
• Model gives data to View which in turn creates a DOM for it
• Now each time data was updated by the Model, View had to create a new DOM for it
• This puts heavy load on View and makes our processing slower.
• With ReactJS, when Model gives data to View if the DOM is empty, React will create a
DOM for it
• Now whenever the data updates, React will create a virtual DOM for it and compare the
current DOM with the previous one
• Once the changes are calculated, it will update the Real DOM with only the elements that
have actually changed
A.Hossam
React Angular
▪ React is a library and not a framework. ▪ Angular is a full-fledged MVC framework.
▪ It is quite simple to understand if you are ▪ Angular uses TypeScript, which takes
familiar with JavaScript. some time to learn.
▪ However, it takes time to learn how to set ▪ Still, Angular is more complex to
up a project properly. understand.
▪ React depends on other libraries to add ▪ Angular itself is a huge library, so initial
functionality. learning effort is worth it.
▪ React was created by Jordan Walke, a ▪ Angular Framework invented by Google It
software engineer at Meta, who released includes set of well integrated libraries to
an early prototype of React called "FaxJS". create single page applications.
▪ He was influenced by XHP, an HTML
component library for PHP.
▪ It was first deployed on Facebook's News
Feed in 2011 and later on Instagram in
2012.
▪ It was open-sourced at JSConf US in May
2013.
➢ Prerequisites of react
• Knowledge of HTML, CSS, JavaScript, and Git
• Knowledge of package management with Node.js and npm
• Node.js and npm locally installed
• A code editor, such as Visual Studio Code
A.Hossam
➢ What is needed to use REACT?
1. Node JS
o Go and download it from (nodejs.org)but make sure first that its not downloaded on
your device use these steps:
▪ Open cmd (terminal) and write node -v
• In front-end development, there are many frameworks and libraries available for front-
end development. Not all of them are good.
• React is one of the most popular and widely used libraries (it’s not a framework) for
frontend development.
• Web developers were taught for years to create HTML, JavaScript, and CSS separately.
React recommends writing HTML and CSS in JavaScript.
• After testing it, this doesn't seem ridiculous.
• Because front-end development is moving toward component-based development.
2. Rich user-interfaces
o React lets you build rich user-interfaces easily.
o Quality of user-interfaces is important because a poorly designed user-interface is
generally less user-friendly, and the users will not like a poorly designed UI.
3. Faster development
o If it takes a huge amount of time to build a simple thing, you’ll lose money.
o On the other hand, if you can deliver products quickly, you can earn cash quickly and
your clients will also be happy.
A.Hossam
6. Strong community support
o The following figure shows that Google gives 82,500,000 results for the search term
‘react tutorial’
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/[email protected]/babel.min.js"></script>
</head>
<body>
<div id="mydiv"></div>
<script type="text/babel">
function Hello() {
return <h1>Hello World!</h1>;
}
const container = document.getElementById('mydiv');
const root = ReactDOM.createRoot(container);
root.render(<Hello />);
</script>
</body>
</html>
• React is an open-source front-end framework
• React introduces JSX, or JavaScript XML
o JSX can be used to create React components
• JSX follows XML rules
o All elements must be placed inside one parent element
o All elements must be closed
<div>
<h1> React </h1>
<p>JSX follows XML rules. All elements must be placed inside one
parent element. All elements must be closed</p>
</div>
A.Hossam
➢ React JS Basic Concepts Reference
• Before grasping its core concepts, we should know how to build a basic react app with the
hello world output.
function App() {
return (
<div className="App">
<h1 style={{ textAlign: 'center' }}>
Hello, world!
</h1>
</div>
);
}
A.Hossam