0-Introduction To React
0-Introduction To React
0-Introduction To React
https://crossbrowsertesting.com/blog/test-automation/history-of-web-browsers/
A lack of standardization
meant that developers had to
account for many different
browser behaviors and edge
cases.
Early jQuery source code
// If Mozilla is used
if (jQuery.browser == 'mozilla' || jQuery.browser == 'opera') {
// Use the handy event callback
jQuery.event.add(document, 'DOMContentLoaded', jQuery.ready);
• Reusable UI components.
• Easier to build and maintain a complex website.
• Declarative paradigm - the developer describes what the UI should
be like.
• Better structure and maintainable programs
• Better tools and testing capability
• Higher performance with lesser effort
Prerequisites
● DOM, common HTML elements, ● Selectors and attributes
attributes and formatting ● Pseudo class/elements
○ Text, forms, tables
○ Images, videos, multimedia ● CSS units - px, %, vw/vh, rem, em
● Accessibility ● Flexbox, Grid
● Hyperlinks ● Colors, gradients, shadows and
● Internationalization borders
● Semantic HTML, HTML versions
https://www.internetingishard.com/html-and-css/basic-web-pages/
Javascript, ES6+
Some important React concepts
• Rendering elements
• Components and their types
• Component tree and decomposability
• Life cycle events
• JSX
• Props, Event
• Mutability and Immutability
• State and updating state
• Functions vs Classes for components
• Hooks
Environment Setup
• Node.js
• npm - Node Package Manager, an online repository of packages + a
command line utility
• npx - A node tool execute npm packages
https://nodejs.org/en/download/
Environment Setup (optional)
index.html
• <div id=“root”>
index.js
• document.getElementById(“root”)
• <App />
App.js
• Definition of the App component
What is React ?
https://reactjs.org/tutorial/tutorial.html#what-is-react
just HTML5
<!DOCTYPE html>
<html lang="en">
<head>
<title>Some title</title>
</head>
<body>
<div>Hello World</div>
</body>
</html>
<!DOCTYPE html>
<title>Some title</title>
</head>
<body>
<script>
document.body.appendChild(helloDiv);
</script>
</body>
</html>
<body> just React
<script
src="https://unpkgcom/.../react.production.min.js"
crossorigin></script>
<script src="https://unpkg.com/.../react-
dom.production.min.js" crossorigin></script>
<script>
const reactElement = React.createElement("div", {
children: "Hello World",
});
ReactDOM.render(reactElement, document.body);
</script>
</body>
</html>
https://reactjs.org/blog/2015/10/07/react-v0.14.html
React,
ReactDOM
ReactNative
…
…
More on React packages
React 16.13.1 Production (12.5KB) -
https://unpkg.com/[email protected]/umd/react.production.min.js
React 16.13.1 Development (105.1KB) -
https://unpkg.com/[email protected]/umd/react.development.js
instead of
https://reactjs.org/docs/dom-elements.html
Expressions in JSX
const name = 'John Doe';
const element = <h1>Hello, {name}</h1>;
function getGreeting(user) {
if (user) {
return <h1>Hello, {formatName(user)}!</h1>;
}
return <h1>Hello, Stranger.</h1>;
}
Components and Props
5231564
● Components let you split the
UI into independent, reusable
pieces, and think about each
piece in isolation.
● Components can refer to other
components in their output. 7 8 9
+
This lets us use the same 4 5 6
component abstraction for any 1 2 3 =
level of detail
x 7 8 9
4 5 6
1 2 3
7 8 9 +
4 5 6
7 8 9 + 1 2 3 =
4 5 6
1 2 3
=
5231564 5231564
7 8 9 + 7 8 9 +
4 5 6 4 5 6
1 2 3 = 1 2 3 =
5231564 5231564
7 8 9
+
7 8 9 4 5 6
+
4 5 6 1 2 3 =
1 2 3 =
Components
• Components are independent
and reusable bits of code.
• They serve the same purpose as
JavaScript functions but work in
isolation and return HTML.
• They accept arbitrary inputs
(called “props”) and return
React elements describing
what should appear on the
screen.
export const Header = ()=> {
return(
<div>
<h1>Hello World</h1>
</div>
)
}
Exercise 2 – Lets create a component
1. Create an Footer.js file
2. Add the following contents
function Footer() {
return (
<div>
This is a footer
</div>
);
}
export default Footer;
3. Import it into the App.js file and add it to inside the function
return import Footer from './Footer’
…
return (<> <p>This is some HTML before the footer</p>
<Footer></Footer> </>);
Components in React
Class Component
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Fun learning react
• https://snake.sebinbenjamin.me
• Weather apps
• Calculators
• To do apps
• https://github.com/Asabeneh/30-Days-Of-React
www.missionreadyhq.com