๐ง Emmet (Shortcuts for HTML/CSS)
- What: A shortcut tool in editors like VS Code to write HTML/CSS faster.
- Why: Saves time by expanding short code into full HTML/CSS.
-
HTML Example:
ul>li*3
โ Expands to: CSS Example:
m10
โ Expands to:
margin: 10px;
Usage: Just type and press Tab.
Library vs Framework
- Library: ๐ You call the code when needed (You decide when and where to use it.) ๐ You are in control. (e.g., React, Lodash)
Framework:
๐ Framework calls your code.
๐ It controls the flow. (It tells when to run your code โ you just โplug inโ your logic.)
(e.g., Angular, Next.js)
โ
Why React is a Library?
- React only handles the UI (view).
- You decide how the rest of the app works.
- It doesnโt force structure or tools.
๐งฉ Tools You Choose in React:
- Routing: react-router-dom
- State: useState, Redux, Zustand, Recoil
- Data Fetching: fetch, axios, React Query, SWR
- Forms: Formik, React Hook Form
- Styling: CSS, SCSS, Tailwind, styled-components
- Testing: Jest, React Testing Library, Cypress
- Build Tools: Vite, Webpack, CRA, Next.js
๐ฏ Summary: React is flexible โ itโs a UI library, not a full framework.
๐ง Soโฆ is Vue a library or a framework?
โก๏ธ Vue 2: Mostly considered a library (like React) โ focuses on the view layer.
โก๏ธ Vue 3 with ecosystem (Vuex, Vue Router, CLI): Becomes a framework.
React Vue 2 โ library ; Vue 3 + Tools Framework-ish ; Angular โ Full Framework
๐ง How does the browser know about document, createElement, etc.?
These come from Browser APIs, not from JavaScript itself.
๐ง How it works:
- The browser has a JavaScript engine (like Chromeโs V8).
- The browser provides built-in objects like: โ window โ document โ console โ localStorage โ fetch, etc.
- These are called Web APIs โ part of the browser environment, not core JavaScript.
๐ Example:
const div = document.createElement(โdivโ);
-
documentcomes from the DOM API. - Itโs not part of core JS โ itโs provided by the browser when JS runs in the browser.
โ ๏ธ Note:
If you run JavaScript outside the browser (like in Node.js),
โ You wonโt get document or window โ because thereโs no DOM.
โ
In short:
JS runs inside the browserโs environment,
and the browser gives extra objects (like document) via Browser APIs.
We can inject react library with a bare minimum thing
What is CDN?
๐ง What is a CDN?
CDN = Content Delivery Network
Itโs a network of distributed servers that deliver files (JS, CSS, images) from the nearest location to the user โ making websites faster and more reliable.
๐ Real-world example:
When you visit a site using a CDN:
If youโre in India, the content may load from a server in Mumbai
If youโre in the US, it loads from a New York or LA server
This minimizes latency and speeds up loading.
๐ฆ How does it relate to React?
React can be included via CDN links instead of installing via npm.
Example:
<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>
๐ง Real-life example of using a CDN:
Letโs say you want to use a **carousel/slider** in your web app.
Instead of downloading the whole library,
you can just include its **CDN link** in your HTML:
html
<! โ Slick Carousel CSS โ
<! โ Slick Carousel JS โ
๐ Why use CDN links?
Quick setup โ no build tools needed
Great for testing or small apps
No need to install Node.js or npm
โ ๏ธ Not ideal for large/production apps โ Use bundlers like Vite or Webpack for better control.
A CDN serves files faster from nearby servers.
Reactโs CDN version lets you use React by just adding tags โ no installation required.</p> <p>๐ง What is <code>crossorigin</code> in a <code><script></code> or <code><link></code> tag?<br> The <code>crossorigin</code> attribute tells the browser how to handle <strong>cross-origin requests</strong> โ when youโre loading files from a <strong>different domain</strong> (like a CDN).</p> <p>โ -</p> <p>๐ Example:<br> </p> <div class="highlight"><pre class="highlight html"><code><span class="nt"><script </span><span class="na">src=</span><span class="s">โhttps://unpkg.com/react@18/umd/react.development.js"</span> <span class="na">crossorigin</span> <span class="nt">></script></span> ๐ง What does *โdifferent domainโ* mean in `crossorigin`? It means the file (like a script or image) is **NOT hosted on your website**, but coming from **another server**. โ - ๐ Example: You made a website: ๐ `https://myportfolio.com` Now, you add this: </code></pre></div> <p><br> html</p> <script src=โhttps://unpkg.com/react@18/umd/react.development.js" crossorigin>
๐ฆ That script is from https://unpkg.com โ a different domain.
So: myportfolio.com โ unpkg.com โ cross-origin request
Different domainโ means the file is loaded from another website/serve
๐ง Shortest React program (with CDN):
<!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>
</head>
<body>
<div id=โrootโ></div>
</body>
</html>|
โ
This runs without any build tools (like npm, Vite, etc.)
โ
Just open in browser โ youโll see: Hello React
why? Because in console write React and it give React object (like windows object). Also React is a global object
React is just a peice of JS code written by meta developers.
Why 2 files : React and ReactDOM ; because react is not just limited to browsers. Thers is react native for mobile, react 3D as well, react also used in rendering engines.
So react@18 is core library of react
react-dom: the web version of react
Heading using React
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="root"></div>
</body>
<script
crossorigin
src="https://unpkg.com/react@18/umd/react.production.min.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
></script>
</html>
<script>
const heading = React.createElement("h1", {}, "Heading using react"); // it taskes 3 argument - 1.the tag 2.object 3.value
</script>
// h1 comes from the core library of react
now heading is created, now we need to put heading into the root element
<script>
const heading = React.createElement("h1", {}, "Heading using react");
const root = ReactDOM.createRoot(document.getElementById("root")); //this tells react what is the root element inside my app. Also here we used ReactDOM because now we are manipulating DOM
root.render(heading) // passing react element inside the root
// So this render method takes react element and injects it into the DOM and modifies it
</script>
๐ง Is `createElement` an API?
Yes โ `React.createElement()` is a **React API**.
Itโs a method provided by the React library to **create React elements** (UI building blocks) without using JSX.
โ -
๐ง Syntax:
js
React.createElement(type, props, children)
if we do:
console.log(heading); // it is plain JS object
// so the react code that meta developers wrote is taking : "h1", {}, "Heading usi
Top comments (0)