Day - 3
Day - 3
React
Day 3 - Topics
• Setting Up using VS Code
• VS Code Extensions for ES6
• Hello World App
• React Essential Features and Syntax
• React Directory Structure
• Overview of Webpack
• Babel
Continuity…
• Live Preview
– Hosts a local server in your workspace for you to
preview your webpages on.
Continuity…
• Live Server
– Launch a development local Server with live reload
feature for static & dynamic pages.
function App() {
return (
<div className="App">
<header className="App-header">
<h1>Hello, World!</h1>
</header>
</div>
);
}
export default App;
Continuity…
function App() {
// ...
}
Continuity…
• Types of Components
– Functional Component
– Class Component
Functional Component
• A functional component in React is a JavaScript function
that returns React elements (typically JSX) to describe
the user interface.
• Class Syntax:
• State:
– Class components can hold and manage local state
using the this.state object.
• Lifecycle Methods:
– Class components have lifecycle methods that are
invoked at different stages of a component's life.
– Example:
const element = <h1>Hello, JSX!</h1>;
Continuity…
• Attributes in JSX:
– JSX uses camelCase for attribute names, similar to
JavaScript object property names. For example,
class in HTML becomes className in JSX.
– ReactDOM.render(<App />,
document.getElementById('root'));
Continuity…
• JSX is Transpiled:
– JSX is not directly understood by browsers, so it
needs to be transpiled into standard JavaScript.
• Learning Curve:
– JSX might introduce a learning curve for developers
who are new to React or modern frontend
development. The syntax resembles XML/HTML,
which may be unfamiliar to some developers.
• Build Tool Dependency:
– JSX requires a build tool like Babel to transpile it
into standard JavaScript that browsers can
understand. This introduces an additional step in the
development process.
Continuity…
• Limited Expressiveness:
– JSX is primarily designed for expressing UI
components. It might not be the best choice for
expressing more complex logic or non-UI-related
code.
• JavaScript Expressions Only:
– JSX allows embedding JavaScript expressions, but
they must be enclosed in curly braces. Statements
(such as if statements or loops) are not directly
allowed within JSX. Instead, you typically use
ternary expressions or map functions.
Thank You