<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Olaniyi Olabode</title>
    <description>The latest articles on DEV Community by Olaniyi Olabode (@niero).</description>
    <link>https://dev.to/niero</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1959853%2Fa3a90150-da50-43d1-bda9-669a9b0c82d9.jpg</url>
      <title>DEV Community: Olaniyi Olabode</title>
      <link>https://dev.to/niero</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/niero"/>
    <language>en</language>
    <item>
      <title>📝How I Built a Fully Automated Telegram Moderation Bot — An Engineering Case Study</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Fri, 28 Nov 2025 13:59:12 +0000</pubDate>
      <link>https://dev.to/niero/how-i-built-a-fully-automated-telegram-moderation-bot-an-engineering-case-study-l3</link>
      <guid>https://dev.to/niero/how-i-built-a-fully-automated-telegram-moderation-bot-an-engineering-case-study-l3</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F023cc7e4uyq2hod63r6p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F023cc7e4uyq2hod63r6p.png" alt=" " width="300" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I built a Telegram bot that automatically detects and handles duplicate messages (spam), promotional messages, and blacklisted keywords; logs every action; tracks infractions in Redis; and provides a clean admin surface (planned) for whitelist and keyword management. It runs on Node + TypeScript, uses Telegraf for Telegram, PostgreSQL for persistent data, and Redis for fast infra counters.&lt;/p&gt;

&lt;p&gt;This article is a detailed, step by step breakdown of the problem, architecture, implementation, testing, monitoring, and deployment. It’s written as a technical case study so you and other engineers can reproduce, audit, or extend the system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1a079kb8etfxph105ien.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1a079kb8etfxph105ien.png" alt=" " width="588" height="1314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why I built this&lt;/li&gt;
&lt;li&gt;Goals &amp;amp; constraints&lt;/li&gt;
&lt;li&gt;Tech stack&lt;/li&gt;
&lt;li&gt;High-level architecture (diagram)&lt;/li&gt;
&lt;li&gt;Data model (schema.sql)&lt;/li&gt;
&lt;li&gt;Core modules — explanation + code snippets&lt;/li&gt;
&lt;li&gt;Message flow&lt;/li&gt;
&lt;li&gt;ensureChat / ensureUser (DB helpers)&lt;/li&gt;
&lt;li&gt;Duplicate detector (Redis + normalization)&lt;/li&gt;
&lt;li&gt;Promo detector&lt;/li&gt;
&lt;li&gt;Keyword blacklist&lt;/li&gt;
&lt;li&gt;Audit logging&lt;/li&gt;
&lt;li&gt;Infractions and auto-ban&lt;/li&gt;
&lt;li&gt;How I tested each feature (step-by-step)&lt;/li&gt;
&lt;li&gt;Monitoring &amp;amp; alerts (production-lite approach)&lt;/li&gt;
&lt;li&gt;Admin frontend (concept + API contract)&lt;/li&gt;
&lt;li&gt;Deployment notes (free options)&lt;/li&gt;
&lt;li&gt;Security &amp;amp; hardening notes&lt;/li&gt;
&lt;li&gt;Future improvements &amp;amp; roadmap&lt;/li&gt;
&lt;li&gt;Appendix: useful commands and snippets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Why I built this&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Telegram groups scale quickly and inevitably attract spam, unwelcome promotions, or repeated posts that lower signal to noise ratio. The goal was a resilient, minimal, low cost system that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protects the group from repeated posts (spam) and ads,&lt;/li&gt;
&lt;li&gt;Logs everything for auditability,&lt;/li&gt;
&lt;li&gt;Lets maintainers whitelist trusted users,&lt;/li&gt;
&lt;li&gt;Remains free-hosting friendly and easy to operate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Goals &amp;amp; constraints&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functional: detect duplicates, detect promos, block blacklisted keywords, warn/delete/ban, persist logs.&lt;/li&gt;
&lt;li&gt;Operational: work on free or cheap infrastructure, be robust, and recoverable.&lt;/li&gt;
&lt;li&gt;Design: simple DB schema, Redis for ephemeral counters, code in TypeScript, clean structure for future admin UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Tech stack&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Language: Node.js + TypeScript&lt;/li&gt;
&lt;li&gt;Telegram SDK: Telegraf&lt;/li&gt;
&lt;li&gt;DB: PostgreSQL (persistent storage)&lt;/li&gt;
&lt;li&gt;Cache / counters: Redis (fast infra counters + TTL)&lt;/li&gt;
&lt;li&gt;Dev tooling: ts-node-dev for development, tsc for build&lt;/li&gt;
&lt;li&gt;Optional admin frontend: React + Vite + Tailwind (planned)&lt;/li&gt;
&lt;li&gt;Hosting: Docker locally for dev; free cloud choices: Render / Railway / Fly / Vercel for frontend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fna6ygyca3dj23growxls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fna6ygyca3dj23growxls.png" alt=" " width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notes:&lt;/p&gt;

&lt;p&gt;DB stores persistent state (chats, users, policies, whitelist, keywords, audit logs).&lt;/p&gt;

&lt;p&gt;Redis stores ephemeral infra counters with TTL (e.g., 24 hours).&lt;/p&gt;

&lt;p&gt;The admin API reads/writes DB and talks to Redis to reset infra keys.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Data model (schema.sql)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the schema used in my project (run it against your Postgres):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- chats
CREATE TABLE IF NOT EXISTS chats (
  chat_id BIGINT PRIMARY KEY,
  title TEXT,
  created_at TIMESTAMP DEFAULT NOW()
);

-- users
CREATE TABLE IF NOT EXISTS users (
  user_id BIGINT PRIMARY KEY,
  first_name TEXT,
  last_name TEXT,
  username TEXT,
  created_at TIMESTAMP DEFAULT NOW()
);

-- policies
CREATE TABLE IF NOT EXISTS policies (
  chat_id BIGINT PRIMARY KEY REFERENCES chats(chat_id) ON DELETE CASCADE,
  duplicate_threshold INT DEFAULT 3,
  created_at TIMESTAMP DEFAULT NOW()
);

-- whitelist
CREATE TABLE IF NOT EXISTS whitelist (
  chat_id BIGINT REFERENCES chats(chat_id) ON DELETE CASCADE,
  user_id BIGINT REFERENCES users(user_id) ON DELETE CASCADE,
  PRIMARY KEY (chat_id, user_id)
);

-- audit logs
CREATE TABLE IF NOT EXISTS audit_logs (
  id SERIAL PRIMARY KEY,
  chat_id BIGINT REFERENCES chats(chat_id) ON DELETE CASCADE,
  user_id BIGINT REFERENCES users(user_id) ON DELETE CASCADE,
  message_id BIGINT,
  rule_triggered TEXT,
  action_taken TEXT,
  message_text TEXT,
  meta JSONB,
  created_at TIMESTAMP DEFAULT NOW()
);

-- keyword blacklist
CREATE TABLE IF NOT EXISTS keyword_blacklist (
  chat_id BIGINT REFERENCES chats(chat_id) ON DELETE CASCADE,
  keyword TEXT,
  PRIMARY KEY(chat_id, keyword)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Core modules — explanation + code snippets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’ll walk through the main parts of the code and explain why they were designed that way. (These are extracts adapted to be readable the full project contains types and helpers.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.1 Message flow (handleMessage)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every chat message passes through this handler:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Persist chat/user&lt;/li&gt;
&lt;li&gt;Skip if whitelisted&lt;/li&gt;
&lt;li&gt;Duplicate detection&lt;/li&gt;
&lt;li&gt;Promo detection&lt;/li&gt;
&lt;li&gt;Keyword blacklist&lt;/li&gt;
&lt;li&gt;Execute action (delete/warn/ban)&lt;/li&gt;
&lt;li&gt;Log action to audit_logs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key points: always use parameterized SQL queries, protect against missing fields (ctx.chat might be undefined in some update types), and catch errors.&lt;/p&gt;

&lt;p&gt;Example (simplified handler):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function handleMessage(ctx: Context) {
  const chatId = ctx.chat?.id;
  const msg = ctx.message;
  if (!chatId || !msg || !("text" in msg) || !msg.text) return;

  const text = msg.text;
  const user = msg.from;
  if (!user) return;

  await ensureChat(chatId, msg.chat.title);
  await ensureUser(user);

  // Whitelist check
  const wl = await query('SELECT 1 FROM whitelist WHERE chat_id=$1 AND user_id=$2', [chatId, user.id]);
  if (wl.rowCount &amp;gt; 0) return;

  // Duplicate detection + infra counter
  // Promo detection
  // Keyword blacklist
  // Logging and actions...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.2 ensureChat / ensureUser (db helpers)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These upsert basic metadata so other tables can reference them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function ensureChat(chatId: number, title?: string) {
  await query(
    `INSERT INTO chats (chat_id, title) VALUES ($1, $2)
     ON CONFLICT (chat_id) DO UPDATE SET title = EXCLUDED.title`,
    [chatId, title || null]
  );
}

export async function ensureUser(user: any) {
  if (!user) return;
  await query(
    `INSERT INTO users (user_id, username, first_name, last_name)
     VALUES ($1, $2, $3, $4)
     ON CONFLICT (user_id) DO UPDATE SET
       username = EXCLUDED.username, first_name = EXCLUDED.first_name, last_name = EXCLUDED.last_name`,
    [user.id, user.username || null, user.first_name || null, user.last_name || null]
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.3 Duplicate detector (Redis + normalizer)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Normalize text (lowercase, trim, collapse whitespace/punctuation optionally)&lt;/li&gt;
&lt;li&gt;Use Redis lists or hashes per user+chat or a key pattern like:&lt;/li&gt;
&lt;li&gt;dup:{chatId}:{userId}:{normalizedText} with TTL&lt;/li&gt;
&lt;li&gt;Simpler: push to a Redis list keyed by dup:{chatId}:{userId}, but we used a hash of message text to counts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementation (conceptual):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pushAndCheckDuplicate(chatId, userId, messageId, text) → returns { duplicateCount }&lt;/li&gt;
&lt;li&gt;If duplicateCount &amp;gt;= DUPLICATE_THRESHOLD → delete+warn and increment infra counter&lt;/li&gt;
&lt;li&gt;Redis usage example:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;// pseudo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const key = `dup:${chatId}:${userId}:${hash(normalizedText)}`;
const count = await redis.incr(key);
await redis.expire(key, DUPLICATE_WINDOW); // e.g., 300s
return { duplicateCount: count };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Infra counter:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Key: infra:${chatId}:${userId} → incr on each duplicated incident, TTL 24h&lt;/p&gt;

&lt;p&gt;When infra &amp;gt;= 3 → bot attempts ctx.banChatMember(user.id) and logs&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.4 Promo detector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A lightweight regex-based detector is fine to start. Typical checks:&lt;/p&gt;

&lt;p&gt;Telegram invites t.me/ or telegram.me/&lt;/p&gt;

&lt;p&gt;URLs with suspicious keywords (channel, group, join)&lt;/p&gt;

&lt;p&gt;Phone numbers or payment links — policy-dependent&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function detectPromo(text: string): boolean {
  // very simple
  return /t\.me\/\w+/.test(text) || /joinchat|telegram\.me/.test(text);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can make this more advanced later (ML / heuristics).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.5 Keyword blacklist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Per chat table keyword_blacklist. On message:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load keywords for chat&lt;/li&gt;
&lt;li&gt;Normalize message text&lt;/li&gt;
&lt;li&gt;Check includes(keyword) on normalized text&lt;/li&gt;
&lt;li&gt;Delete + warn + log&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reason to store in DB: admins can edit keywords and changes are persistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.6 Audit logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every action writes a row to audit_logs. Keep meta as JSON for flexible data (duplicate counts, infra counts, matched keyword). Example call:&lt;/p&gt;

&lt;p&gt;await logAudit(chatId, user.id, msg.message_id, "duplicate", "deleted+warn", text, { duplicateCount });&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. How I tested each feature (step-by-step)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Testing is crucial. Here’s the exact process I used while developing locally (Docker):&lt;/p&gt;

&lt;p&gt;Testing is crucial. Here’s the exact process I used while developing locally (Docker):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup (dev)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run Postgres + Redis in Docker Compose.&lt;/li&gt;
&lt;li&gt;Start bot in dev (npm run dev).&lt;/li&gt;
&lt;li&gt;Invite bot to a test group and send messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Duplicate detection&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ensure not whitelisted.&lt;/li&gt;
&lt;li&gt;Send Hi three times.&lt;/li&gt;
&lt;li&gt;Expect:&lt;/li&gt;
&lt;li&gt;On 3rd message, bot deletes the last message and warns the user.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Redis key infra:: increments after repeated offenses.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Check audit_logs for rule_triggered = 'duplicate'.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Promo detection&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Send Check this channel: t.me/something.&lt;/li&gt;
&lt;li&gt;Expect deletion, a warning, and audit_logs row rule_triggered = 'promo'.
**
Keyword blacklist**&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Insert keyword into DB:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO keyword_blacklist (chat_id, keyword)
VALUES (&amp;lt;CHAT_ID&amp;gt;, 'spoiler')
ON CONFLICT DO NOTHING;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Send a message containing spoiler.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Expect deletion + warning + audit log.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whitelist&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Insert whitelist entry:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO whitelist (chat_id, user_id)
VALUES (&amp;lt;CHAT_ID&amp;gt;, &amp;lt;USER_ID&amp;gt;)
ON CONFLICT DO NOTHING;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Send spam/promo/keyword messages — expect bot to ignore.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Audit logging&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Trigger each rule&lt;/li&gt;
&lt;li&gt;Query audit_logs to verify message text, rule trigger, action, and meta.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Infra / Ban&lt;/strong&gt;&lt;br&gt;
To test real banning, use a non-admin test account (bot cannot ban owners/admins). Repeat infra-causing actions to trigger ban and confirm user is removed from group.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Monitoring &amp;amp; alerts (production-lite)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I wanted something free, reliable, and simple to operate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8.1 Logging&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use winston or pino to write structured logs to files + console.&lt;/li&gt;
&lt;li&gt;Keep logs in JSON for easy parsing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8.2 Admin alerts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On critical errors (unhandled exceptions, DB connection errors), notify a private Telegram admin chat:&lt;/p&gt;

&lt;p&gt;// example on error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await bot.telegram.sendMessage(ADMIN_CHAT_ID, `Bot error: ${err.message}`);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8.3 Health checks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Expose /health endpoint on the admin API that checks:

&lt;ul&gt;
&lt;li&gt;DB connectivity&lt;/li&gt;
&lt;li&gt;Redis connectivity&lt;/li&gt;
&lt;li&gt;Bot can call getMe or similar&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Use a free uptime monitor (UptimeRobot) to ping /health every 5 minutes and notify you by email if it fails.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8.4 Metrics (basic)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Periodically compute counts (audit logs per day) and send a digest to admin chat (once per day).&lt;/li&gt;
&lt;li&gt;Optional: lightweight Prometheus client + Grafana later (overkill for now).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Admin frontend (concept + API contract)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I planned a React admin frontend with the following responsibilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CRUD for whitelist and blacklist&lt;/li&gt;
&lt;li&gt;View &amp;amp; filter audit logs&lt;/li&gt;
&lt;li&gt;Edit policies (duplicate threshold, promo action)&lt;/li&gt;
&lt;li&gt;Reset infra counters (calls Redis)&lt;/li&gt;
&lt;li&gt;Dashboard metrics &amp;amp; charts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;API contract (examples):&lt;/p&gt;

&lt;p&gt;`- GET /api/chats?page=1&amp;amp;size=20 → list chats&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET /api/chats/:chatId → chat detail with policies, whitelist, keywords&lt;/li&gt;
&lt;li&gt;POST /api/chats/:chatId/whitelist → add whitelist&lt;/li&gt;
&lt;li&gt;DELETE /api/chats/:chatId/whitelist/:userId → remove whitelist&lt;/li&gt;
&lt;li&gt;POST /api/reset-infra → body { chatId, userId } (backend clears Redis key)`&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The frontend starts with a mock API so development is frictionless. When ready, swap VITE_API_BASE_URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Deployment notes (free options)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend (bot + admin API)&lt;/li&gt;
&lt;li&gt;Deploy as Docker containers (Render, Railway, Fly). Railway/Render provide free tiers for small projects — good for prototyping.&lt;/li&gt;
&lt;li&gt;Ensure PG and Redis are persistent volumes or managed services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Frontend&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy the React app on Vercel or Netlify (both have free tiers and easy integration).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Production considerations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use environment variables for BOT_TOKEN, DATABASE_URL, REDIS_URL.&lt;/li&gt;
&lt;li&gt;Use a process manager or container auto-restart to keep bot up.&lt;/li&gt;
&lt;li&gt;Add daily backups for Postgres (use pg_dump or provider snapshots).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;11. Security &amp;amp; hardening&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Never commit tokens. Use env variables and secrets manager where possible.&lt;/li&gt;
&lt;li&gt;SQL safety: use parameterized queries — no string concatenation.&lt;/li&gt;
&lt;li&gt;Rate limits: respect Telegram API limits (avoid mass requests).&lt;/li&gt;
&lt;li&gt;Permissions: bot should have only the permissions it needs in the group (delete messages, ban members only if necessary).&lt;/li&gt;
&lt;li&gt;Admin API: protect with a token. Later add OAuth / Telegram login if needed.&lt;/li&gt;
&lt;li&gt;Error reporting: do not leak sensitive info in alerts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;12. Future improvements &amp;amp; roadmap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Short term:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add admin UI (React) and wire to real admin API&lt;/li&gt;
&lt;li&gt;Add more flexible penalty steps (mute → temp ban → perm ban)&lt;/li&gt;
&lt;li&gt;Better normalization for duplicates (strip emojis, repeated punctuation)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mid-term:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ML based spam classifier to reduce false positives&lt;/li&gt;
&lt;li&gt;Bulk audit exports, per-chat analytics&lt;/li&gt;
&lt;li&gt;Multi-bot management (SaaS style)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Long term:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SaaS: multi-tenant admin console, billing, onboarding flows&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Appendix — useful commands &amp;amp; snippets
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3.8"
services:
  postgres:
    image: postgres:15
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: telegram_bot
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data

  redis:
    image: redis:7
    ports:
      - "6379:6379"

volumes:
  pgdata:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply DB schema (copy schema.sql into container, then run)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker cp schema.sql telegram-bot-postgres-1:/schema.sql
docker exec -i telegram-bot-postgres-1 psql -U postgres -d telegram_bot -f /schema.sql

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reset infra in Redis&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it telegram-bot-redis-1 redis-cli
DEL infra:&amp;lt;chatId&amp;gt;:&amp;lt;userId&amp;gt;
GET infra:&amp;lt;chatId&amp;gt;:&amp;lt;userId&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run bot in dev&lt;/p&gt;

&lt;p&gt;npm install&lt;br&gt;
npm run dev   # uses ts-node-dev&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closing notes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project shows how much you can achieve with a small, well-designed stack: Telegraf + Postgres + Redis + a bit of Node glue. The important design principles I applied were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep persistent vs ephemeral data separate (Postgres vs Redis)&lt;/li&gt;
&lt;li&gt;Keep logic stateless where possible and log all decisions for auditability&lt;/li&gt;
&lt;li&gt;Keep admin controls outside the bot (admin API + frontend) so operators can change rules without redeploying the bot&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tell me if you like the github repo and I will push to github for you&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>development</category>
      <category>telegram</category>
    </item>
    <item>
      <title>🚀 The Journey of Building an AI Like ChatGPT</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Mon, 22 Sep 2025 13:29:16 +0000</pubDate>
      <link>https://dev.to/niero/the-journey-of-building-an-ai-like-chatgpt-16k0</link>
      <guid>https://dev.to/niero/the-journey-of-building-an-ai-like-chatgpt-16k0</guid>
      <description>&lt;p&gt;Imagine this: you’ve been hired to create a machine that can talk like a human. People want it to answer questions, write essays, tell jokes even explain code. Sounds impossible, right?  &lt;/p&gt;

&lt;p&gt;Well, that’s exactly what the creators of ChatGPT set out to do.&lt;br&gt;&lt;br&gt;
Let me take you on the &lt;strong&gt;step-by-step journey&lt;/strong&gt; of how such an AI is built.  &lt;/p&gt;

&lt;h2&gt;
  
  
  📚 Step 1 — The Library of Humanity (Data Collection)
&lt;/h2&gt;

&lt;p&gt;First, you need knowledge. Not just a few books but the entire internet’s worth of text:  articles, books, code snippets, conversations. Think of this as walking into the &lt;strong&gt;largest library in history&lt;/strong&gt; and telling your AI:  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Read everything.”&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;That’s the starting point — feeding it data.  &lt;/p&gt;

&lt;h2&gt;
  
  
  👨‍🎓 Step 2 — Teaching the Intern (Training)
&lt;/h2&gt;

&lt;p&gt;Now, imagine you hire an intern. They’ve read the entire library, but they don’t actually understand anything yet. So you start quizzing them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“What comes after &lt;em&gt;The cat sat on the…&lt;/em&gt;?”
&lt;/li&gt;
&lt;li&gt;“Translate this sentence.”
&lt;/li&gt;
&lt;li&gt;“Classify this email as spam or not spam.”
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every time the intern gets it wrong, you nudge them in the right direction. This is &lt;strong&gt;training the model&lt;/strong&gt; adjusting billions of “knobs” (&lt;em&gt;parameters&lt;/em&gt;)&lt;br&gt;&lt;br&gt;
until it starts predicting the right answers.  &lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 Step 3 — The Brain Upgrade (Deep Learning Models)
&lt;/h2&gt;

&lt;p&gt;But your intern is no ordinary student. They have a massive brain made of &lt;strong&gt;layers of artificial neurons&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Each layer learns a slightly different thing: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Letters
&lt;/li&gt;
&lt;li&gt;Words
&lt;/li&gt;
&lt;li&gt;Sentences
&lt;/li&gt;
&lt;li&gt;Meaning
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result? A system that doesn’t just parrot words,&lt;br&gt;&lt;br&gt;
but starts to capture the &lt;em&gt;structure&lt;/em&gt; of human language.  &lt;/p&gt;

&lt;h2&gt;
  
  
  🗣️ Step 4 — From Student to Speaker (Inference)
&lt;/h2&gt;

&lt;p&gt;Training is done. Now, it’s time to test.&lt;br&gt;&lt;br&gt;
You give the AI a prompt: 👉 &lt;em&gt;“Write me a poem about the stars in the style of Shakespeare.”&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;It looks at everything it has learned and predicts, word by word, what should come next.  &lt;/p&gt;

&lt;p&gt;Suddenly, the machine &lt;em&gt;talks&lt;/em&gt;. Not because it “understands,” but because it’s gotten really, really good at predicting what words belong together.  &lt;/p&gt;

&lt;h2&gt;
  
  
  🎓 Step 5 — The Polishing School (Fine Tuning)
&lt;/h2&gt;

&lt;p&gt;Of course, raw predictions can be clumsy. Sometimes the intern rambles. Sometimes they say unsafe or biased things. So you send them to finishing school &lt;strong&gt;fine tuning&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Here, human trainers step in:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Good answers get rewarded 👍
&lt;/li&gt;
&lt;li&gt;Bad answers get corrected 👎
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This reinforcement makes the AI more polite, helpful, and safe for everyday use.  &lt;/p&gt;

&lt;h2&gt;
  
  
  🛡️ Step 6 — Guardrails and Rules (Safety)
&lt;/h2&gt;

&lt;p&gt;Even the best intern needs rules. You add guardrails so the AI won’t:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reveal private information
&lt;/li&gt;
&lt;li&gt;Give harmful advice
&lt;/li&gt;
&lt;li&gt;Go off on wild tangents
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where &lt;strong&gt;ethics, policies, and safeguards&lt;/strong&gt; come in.&lt;br&gt;&lt;br&gt;
Because powerful tools need responsible handling.  &lt;/p&gt;

&lt;h2&gt;
  
  
  🎉 Step 7 — Graduation Day (Deployment)
&lt;/h2&gt;

&lt;p&gt;Finally, the AI is ready to graduate.&lt;br&gt;&lt;br&gt;
You deploy it into apps, websites, and tools where people can use it for work, study, or fun. But just like any graduate, it keeps learning. Developers monitor feedback, retrain when necessary, and release better versions.  &lt;/p&gt;

&lt;h2&gt;
  
  
  🌍 The Bigger Picture
&lt;/h2&gt;

&lt;p&gt;ChatGPT isn’t magic. It’s the result of:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt; (the library of humanity)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Training&lt;/strong&gt; (teaching the intern)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Models&lt;/strong&gt; (the deep brain layers)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-tuning&lt;/strong&gt; (human guidance)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safety&lt;/strong&gt; (guardrails)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment&lt;/strong&gt; (graduation into the real world)
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At the end of the day, AI is a mirror.&lt;br&gt;&lt;br&gt;
It reflects us our words, our knowledge, our creativity.&lt;br&gt;&lt;br&gt;
The better we teach it, the better it becomes.  &lt;/p&gt;

&lt;p&gt;💡 Next time someone says &lt;em&gt;“AI is scary”&lt;/em&gt; or &lt;em&gt;“AI is magic”&lt;/em&gt;,&lt;br&gt;&lt;br&gt;
you can tell them:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“No — it’s just a very fast intern who read everything and learned to guess really well.”&lt;/strong&gt; And that, my friend, is how something like ChatGPT is built.  &lt;/p&gt;

&lt;p&gt;✨ &lt;em&gt;If you enjoyed this breakdown, follow me I’ll be sharing more step-by-step guides&lt;br&gt;&lt;br&gt;
on how AI works and how you can use it in real projects.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;👉 Drop a comment and tell me what you like to see next. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>chatgpt</category>
      <category>programming</category>
    </item>
    <item>
      <title>🤖 What AI Really Is Explained in the Simplest Way Possible</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Sat, 20 Sep 2025 15:11:56 +0000</pubDate>
      <link>https://dev.to/niero/what-ai-really-is-explained-in-the-simplest-way-possible-14ij</link>
      <guid>https://dev.to/niero/what-ai-really-is-explained-in-the-simplest-way-possible-14ij</guid>
      <description>&lt;p&gt;Artificial Intelligence. Two words that dominate headlines, spark debates, and inspire both excitement and fear. But for most people, AI feels mysterious like magic that only scientists and engineers can understand.&lt;/p&gt;

&lt;p&gt;The truth is, AI isn’t magic. It’s not some “thinking robot.” At its core, AI is much simpler:&lt;/p&gt;

&lt;p&gt;👉 AI is just a very powerful pattern recognizer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. How AI Works (No Jargon)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You feed an AI system a massive amount of data (words, images, audio, numbers, anything).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The system looks for patterns in that data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you give it something new, it tries to predict the most likely answer based on those patterns.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it. No brain. No emotions. Just math spotting patterns at superhuman speed.&lt;/p&gt;

&lt;p&gt;Think of it like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Your phone’s autocorrect predicting the next word.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Spotify suggesting your next favorite song.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Netflix recommending a movie.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ChatGPT and other advanced AIs do the same thing just at a much bigger scale, trained on billions of examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. AI Is Like a Super-Fast Intern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s a way to think about AI: imagine you hire an intern who&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Has read every book, article, and blog post ever written.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can type and calculate faster than anyone alive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can draft, summarize, or explain things instantly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sounds amazing, right?&lt;/p&gt;

&lt;p&gt;But this intern has a big flaw: they don’t actually understand what they’re saying. They’re just very good at recognizing patterns and repeating them. Sometimes they’ll make mistakes or confidently give wrong answers.&lt;/p&gt;

&lt;p&gt;That’s AI. Incredibly powerful, but not human.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. AI in Your Everyday Life&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most people don’t realize they’re already using AI daily:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Google Maps → predicts traffic and suggests faster routes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;E-commerce sites → recommend products you’ll probably like.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Voice assistants → understand and respond to your speech.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Photo apps → automatically recognize faces and objects.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI isn’t just in futuristic robots — it’s quietly running behind the apps and tools you already rely on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Why Do We Call It “Intelligence”?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s called Artificial Intelligence because AI can perform tasks we normally associate with human thinking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Writing text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recognizing images.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Translating languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Playing complex games like chess or Go.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But here’s the key: AI doesn’t “understand” like humans do.&lt;br&gt;
It doesn’t know meaning. It doesn’t have consciousness. It just calculates probabilities faster than we can.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Why AI Is Such a Big Deal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If AI is just pattern recognition, why is it so powerful? Because of scale.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A human doctor might study thousands of cases in a lifetime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An AI system can analyze millions of medical records in days, spotting patterns humans might miss.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A customer service rep might answer 50 tickets a day.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An AI chatbot can respond to thousands in seconds.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI doesn’t replace human intelligence, but it amplifies it. That’s why it’s transforming industries like healthcare, finance, education, logistics, and art&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. The Takeaway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI isn’t magic. It isn’t alive. It isn’t smarter than humans in the way we think of intelligence.&lt;/p&gt;

&lt;p&gt;👉 AI is a giant calculator for patterns.&lt;/p&gt;

&lt;p&gt;The real power of AI isn’t in the math itself it’s in how we apply it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To detect diseases earlier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To make transportation safer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To create new forms of art.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To make knowledge more accessible.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The question isn’t whether AI will shape our future.&lt;br&gt;
The question is: how will we choose to use it?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What the Heck is “Vibe Coding”? (And Why Developers Can’t Stop Talking About It)</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Fri, 19 Sep 2025 22:57:28 +0000</pubDate>
      <link>https://dev.to/niero/what-the-heck-is-vibe-coding-and-why-developers-cant-stop-talking-about-it-ko</link>
      <guid>https://dev.to/niero/what-the-heck-is-vibe-coding-and-why-developers-cant-stop-talking-about-it-ko</guid>
      <description>&lt;p&gt;The first time I heard the term “vibe coding,” I laughed. It sounded like something out of a meme like coding while listening to lo-fi beats and hoping the bugs fix themselves.&lt;/p&gt;

&lt;p&gt;But then it happened to me.&lt;/p&gt;

&lt;p&gt;One evening, I had to spin up a quick API for a side project. Normally, that would mean hours of boilerplate: setting up routes, connecting to MongoDB, wiring JWT authentication. Instead, I opened my AI powered editor and typed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
“Create an Express.js API with register, login, and profile endpoints. Use JWT for auth and connect it to MongoDB.”

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I expected a mess. But in seconds, the screen filled with code. A few tweaks later, it was running. That was my first taste of vibe coding  describing the vibe of what you want to build and letting the AI draft it for you.&lt;/p&gt;

&lt;p&gt;It’s not a new framework, not a hidden library it’s more like pair programming with an overeager intern. You give it directions, it produces something fast, and you spend your time steering, correcting, and refining.&lt;/p&gt;

&lt;p&gt;Of course, it’s not magic. Sometimes the AI gives you code that looks right but fails silently. Other times it writes solutions you’d never put in production. Debugging its mistakes feels like reading someone else’s half-finished homework.&lt;/p&gt;

&lt;p&gt;Still, I couldn’t ignore the shift. Instead of spending hours on setup, I could jump straight to the interesting parts. The boring, repetitive code? Offloaded. The big picture? That’s where I stayed focused.&lt;/p&gt;

&lt;p&gt;That’s the heart of vibe coding: moving away from how to build and leaning into what to build. You don’t dictate every keystroke; you describe the outcome, then step in as the editor, the architect, the quality gatekeeper.&lt;/p&gt;

&lt;p&gt;And maybe just maybe that’s where development is headed. In a few years, coding might look less like typing out functions and more like crafting the perfect prompt. The job won’t disappear, but the skillset will shift: clarity, guidance, and knowing when to take back the wheel.&lt;/p&gt;

&lt;p&gt;So what is vibe coding? It’s the messy, exciting middle ground between human creativity and AI autocomplete. It’s coding by description, shaping ideas into software with less grind and more flow.&lt;/p&gt;

&lt;p&gt;It’s real, it’s imperfect and if you haven’t tried it yet, you probably will soon.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>vibecoding</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Level Up Your HTML Game with html-tags-utils</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Fri, 24 Jan 2025 23:42:59 +0000</pubDate>
      <link>https://dev.to/niero/level-up-your-html-game-with-html-tags-utils-cbj</link>
      <guid>https://dev.to/niero/level-up-your-html-game-with-html-tags-utils-cbj</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffp1l9b04hbzm113laeza.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffp1l9b04hbzm113laeza.jpeg" alt=" " width="800" height="450"&gt;&lt;/a&gt;As web developers, we deal with HTML every day. It’s the backbone of everything we build on the web. Yet, how often do we wish we had a more efficient way to manage HTML tags, validate them, or get detailed metadata about their attributes? That’s exactly why I created &lt;strong&gt;&lt;code&gt;html-tags-utils&lt;/code&gt;&lt;/strong&gt; a package that takes working with HTML tags to a whole new level. &lt;/p&gt;

&lt;p&gt;If you’re looking for a tool that combines comprehensive utilities, detailed metadata, and advanced features for HTML tags, you’re in the right place.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why &lt;code&gt;html-tags-utils&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Let’s be honest, writing or managing HTML tags isn’t the most exciting part of web development. That’s where tools like the &lt;strong&gt;&lt;code&gt;html-tags&lt;/code&gt;&lt;/strong&gt; package come in, giving us a simple list of all valid HTML tags. But I needed more. &lt;/p&gt;

&lt;p&gt;I wanted a tool that could answer questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this tag valid in HTML?&lt;/li&gt;
&lt;li&gt;Is this a self-closing (void) tag?&lt;/li&gt;
&lt;li&gt;Which tags have a specific attribute, like &lt;code&gt;href&lt;/code&gt; or &lt;code&gt;src&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;How can I group, filter, or sort tags more efficiently?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, I built &lt;code&gt;html-tags-utils&lt;/code&gt; to fill that gap. It extends the functionality of &lt;code&gt;html-tags&lt;/code&gt; by offering &lt;strong&gt;detailed metadata, validation tools, and filtering utilities&lt;/strong&gt; to make working with HTML smarter and faster.&lt;/p&gt;




&lt;h2&gt;
  
  
  Features You’ll Love
&lt;/h2&gt;

&lt;p&gt;Here’s what makes &lt;code&gt;html-tags-utils&lt;/code&gt; stand out:  &lt;/p&gt;

&lt;h3&gt;
  
  
  🚀 &lt;strong&gt;All HTML Tags&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Get a complete list of all standard HTML tags at your fingertips.&lt;/p&gt;

&lt;h3&gt;
  
  
  🌀 &lt;strong&gt;Void Tags&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Easily identify self-closing tags like &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  📚 &lt;strong&gt;Detailed Metadata&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Access detailed information about each tag, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Descriptions&lt;/li&gt;
&lt;li&gt;Supported attributes&lt;/li&gt;
&lt;li&gt;Categories (e.g., Inline, Block, Interactive)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠️ &lt;strong&gt;Utilities&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Supercharge your workflow with utilities that allow you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filter tags by prefix&lt;/li&gt;
&lt;li&gt;Sort tags alphabetically (ascending or descending)&lt;/li&gt;
&lt;li&gt;Group tags by length&lt;/li&gt;
&lt;li&gt;Search for tags by supported attributes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✅ &lt;strong&gt;Validation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Quickly check if a tag is valid or if it’s a void/self-closing tag.&lt;/p&gt;




&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Getting started is simple. Install the package via npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;html-tags-utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;Here’s a sneak peek into what &lt;code&gt;html-tags-utils&lt;/code&gt; can do for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Get All HTML Tags&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;htmlTags&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html-tags-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlTags&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; ['a', 'abbr', 'address', 'article', …]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. &lt;strong&gt;Identify Void Tags&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;voidHtmlTags&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html-tags-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;voidHtmlTags&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; ['area', 'base', 'br', 'col', 'embed', 'img', …]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;strong&gt;Check if a Tag is Valid&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isHtmlTag&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html-tags-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isHtmlTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isHtmlTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;custom-tag&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. &lt;strong&gt;Filter Tags by Prefix&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;filterTags&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html-tags-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filterTags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; ['data', 'datalist', 'dd', 'del', 'details', 'dialog', 'div', 'dl', 'dt']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. &lt;strong&gt;Get Tags by Supported Attribute&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getTagsByAttribute&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html-tags-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getTagsByAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;href&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; ['a', 'area', 'link', 'base']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How It Compares to &lt;code&gt;html-tags&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;If you’re familiar with the &lt;strong&gt;&lt;code&gt;html-tags&lt;/code&gt;&lt;/strong&gt; package, you’ll appreciate how &lt;code&gt;html-tags-utils&lt;/code&gt; takes things further. Here’s a quick comparison:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;&lt;code&gt;html-tags&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;html-tags-utils&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;List of HTML Tags&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Void Tags&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Detailed Tag Metadata&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tag Validation&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filter Tags by Prefix&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sort Tags Alphabetically&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Group Tags by Length&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Search by Attribute&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Use Cases You’ll Actually Need
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging HTML&lt;/strong&gt;&lt;br&gt;
When debugging, you can quickly validate if a tag is correct or check if it’s self-closing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Tag Management&lt;/strong&gt;&lt;br&gt;
Need to create a list of valid tags dynamically? Use the filtering and grouping utilities to generate exactly what you need.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Web Development Tools&lt;/strong&gt;&lt;br&gt;
Build smarter components or tools by integrating metadata about HTML tags, like descriptions and attributes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Contributing
&lt;/h2&gt;

&lt;p&gt;I’d love to have your input! Feel free to open issues or submit pull requests on GitHub. Let’s make &lt;code&gt;html-tags-utils&lt;/code&gt; even better together.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nierowheezy/html-tags-utils" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;Whether you’re a seasoned developer or just getting started, &lt;code&gt;html-tags-utils&lt;/code&gt; is here to make your work with HTML tags easier, faster, and smarter. It’s built for developers who want &lt;strong&gt;more functionality and flexibility&lt;/strong&gt; than what existing tools offer.  &lt;/p&gt;

&lt;p&gt;Try it out, and let me know what you think!  &lt;/p&gt;

&lt;p&gt;If you ❤️ the package, consider starring it on &lt;a href="https://github.com/nierowheezy/html-tags-utils/stargazers" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; or sharing it with your developer community. 🚀  &lt;/p&gt;

&lt;p&gt;Got feedback? Let’s connect on &lt;a href="https://twitter.com/__nierowheezy" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; or &lt;a href="https://github.com/nierowheezy/html-tags-utils/issues" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Check it out and take your HTML game to the next level!&lt;/strong&gt;  &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>html</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>React Custom Hook: useDarkSwitch</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Sat, 18 Jan 2025 22:42:31 +0000</pubDate>
      <link>https://dev.to/niero/react-custom-hook-usedarkswitch-180g</link>
      <guid>https://dev.to/niero/react-custom-hook-usedarkswitch-180g</guid>
      <description>&lt;p&gt;In a world where users increasingly demand personalized experiences, enabling a smooth and effortless dark mode toggle for your application is no longer just an optional enhancement it's a necessity. Enter &lt;strong&gt;useDarkSwitch&lt;/strong&gt;, the custom React hook that does all the heavy lifting for you. Seamlessly toggle between light and dark themes, sync with system preferences, and enhance your app’s user experience with a robust and intuitive API.&lt;/p&gt;

&lt;p&gt;Whether you're building a sleek portfolio website, a productivity app, or a complex dashboard, &lt;code&gt;useDarkSwitch&lt;/code&gt; is the perfect utility to elevate your project. Let’s dive into why this hook is a game changer for developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why You Need useDarkSwitch
&lt;/h2&gt;

&lt;p&gt;Dark mode isn’t just a trend it’s a user expectation. Beyond aesthetics, it reduces eye strain, conserves battery life on OLED screens, and adapts to the user’s environment. Implementing a reliable dark mode solution, however, can be surprisingly tricky. That’s where &lt;strong&gt;useDarkSwitch&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;Here’s why you’ll love it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Developer Friendly&lt;/strong&gt;: Intuitive API with sensible defaults, so you can integrate it in minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customizable&lt;/strong&gt;: Tailor it to your application’s needs with options for storage providers, class names, and transition durations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sync with System Preferences&lt;/strong&gt;: Automatically adapt to the user’s system theme settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persist User Preferences&lt;/strong&gt;: Save and retrieve the theme mode with localStorage or a custom storage provider.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive and Accessible&lt;/strong&gt;: Ensure your app stays relevant to a diverse audience.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Features of useDarkSwitch
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Effortless Integration
&lt;/h3&gt;

&lt;p&gt;Setting up &lt;code&gt;useDarkSwitch&lt;/code&gt; is straightforward. With minimal configuration, you can have a fully functional theme toggle up and running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useDarkSwitch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use-dark-switch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggle&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggle&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Switch to &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; Mode
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simplicity empowers you to focus on your app’s core functionality while delivering an elevated user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Full Customizability
&lt;/h3&gt;

&lt;p&gt;Customize every aspect of the hook to suit your app’s requirements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;enable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;disable&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;defaultMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;storageKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-theme&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;classNameDark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-dark-mode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;classNameLight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-light-mode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;transitionDuration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Default Mode&lt;/strong&gt;: Set the initial theme.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage Key&lt;/strong&gt;: Define a custom key for saving user preferences.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Class Names&lt;/strong&gt;: Apply custom styles for your themes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transition Duration&lt;/strong&gt;: Smoothly animate theme changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Sync with System Theme
&lt;/h3&gt;

&lt;p&gt;Modern users expect apps to reflect their system preferences. With &lt;code&gt;useDarkSwitch&lt;/code&gt;, you can achieve this effortlessly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;systemTheme&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;syncWithSystem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The hook listens to system theme changes in real-time, ensuring your app remains in sync without additional overhead.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Custom Storage Providers
&lt;/h3&gt;

&lt;p&gt;Need to store preferences in a unique way, such as a server-side session or an IndexedDB instance? &lt;code&gt;useDarkSwitch&lt;/code&gt; supports custom storage providers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;customStorage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sessionStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sessionStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sessionStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;storageProvider&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;customStorage&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Callback Support
&lt;/h3&gt;

&lt;p&gt;Leverage the &lt;code&gt;onChange&lt;/code&gt; callback to execute additional logic whenever the theme changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;toggle&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Theme changed to: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes it easier to integrate analytics, logging, or other side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Smooth Transitions
&lt;/h3&gt;

&lt;p&gt;Enhance user experience by adding transitions to theme changes. Define a duration, and &lt;code&gt;useDarkSwitch&lt;/code&gt; handles the rest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isTransitioning&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;transitionDuration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggle&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;disabled&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isTransitioning&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    Toggle Theme
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SEO Benefits of Adding Dark Mode
&lt;/h2&gt;

&lt;p&gt;Implementing dark mode using &lt;code&gt;useDarkSwitch&lt;/code&gt; can indirectly improve your app’s search engine rankings. How? By boosting user experience and engagement metrics. When users spend more time on your site and interact with its features, search engines take note. A happy user often equals better SEO performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Future of Theming in React
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useDarkSwitch&lt;/code&gt; embodies the future of React development—modular, customizable, and user-focused. As the ecosystem evolves, such utilities will become indispensable for creating modern, responsive, and accessible applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Started Today
&lt;/h2&gt;

&lt;p&gt;Ready to level up your React app? Install &lt;code&gt;useDarkSwitch&lt;/code&gt; and start building:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;use-dark-switch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Join the growing community of developers who trust &lt;code&gt;useDarkSwitch&lt;/code&gt; to deliver seamless dark mode functionality. For detailed documentation, visit the &lt;a href="https://github.com/nierowheezy/use-dark-switch" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;With &lt;code&gt;useDarkSwitch&lt;/code&gt;, theming has never been this elegant. Embrace the power of dark mode and watch your app shine or, in this case, darken! Start building smarter, more intuitive experiences today.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>useDarkSwitch: Empower Your Applications with Seamless Dark Mode</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Sat, 18 Jan 2025 22:34:04 +0000</pubDate>
      <link>https://dev.to/niero/usedarkswitch-empower-your-applications-with-seamless-dark-mode-4odj</link>
      <guid>https://dev.to/niero/usedarkswitch-empower-your-applications-with-seamless-dark-mode-4odj</guid>
      <description>&lt;h1&gt;
  
  
  useDarkSwitch: Empower Your Applications with Seamless Dark Mode
&lt;/h1&gt;

&lt;p&gt;Dark mode is no longer a luxury it’s a necessity. From reducing eye strain to saving device battery life, the demand for dark mode has soared. Enter &lt;strong&gt;useDarkSwitch&lt;/strong&gt;, a powerful, lightweight React hook designed to simplify the implementation of dark mode in your applications. This isn’t just a tool—it’s a game-changer for developers seeking efficiency and elegance.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is useDarkSwitch?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;useDarkSwitch&lt;/strong&gt; is a React hook that lets you toggle between light and dark themes with minimal setup. Forget the hassle of building complex toggling mechanisms or managing theme states manually. With useDarkSwitch, you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Integration:&lt;/strong&gt; Plug and play functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customizability:&lt;/strong&gt; Define themes and transitions as per your needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synchronization:&lt;/strong&gt; Automatically syncs with user system preferences.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're building a portfolio site, a complex dashboard, or a mobile-first application, useDarkSwitch fits seamlessly into any project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Choose useDarkSwitch?
&lt;/h2&gt;

&lt;p&gt;The digital world moves fast, and so do users' expectations. Here’s why useDarkSwitch stands out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Minimal Setup:&lt;/strong&gt; With just a few lines of code, you’re good to go.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;System Preference Support:&lt;/strong&gt; It respects the user's OS-level dark mode setting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customizable Themes:&lt;/strong&gt; Tailor the look and feel to align with your branding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight:&lt;/strong&gt; No unnecessary bloat, ensuring peak performance.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useDarkSwitch&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use-dark-switch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDarkMode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleDarkMode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isDarkMode&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#fff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isDarkMode&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#fff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Welcome&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;Dark&lt;/span&gt; &lt;span class="nx"&gt;Mode&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggleDarkMode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Toggle&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How useDarkSwitch Works
&lt;/h2&gt;

&lt;p&gt;Behind the scenes, &lt;strong&gt;useDarkSwitch&lt;/strong&gt; leverages modern web APIs like &lt;code&gt;matchMedia&lt;/code&gt; and localStorage. This ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;System-Level Integration:&lt;/strong&gt; It listens to changes in system preferences.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistence:&lt;/strong&gt; Your users’ theme preferences are saved across sessions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt; You can override system settings when needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  SEO and Visibility Challenges
&lt;/h2&gt;

&lt;p&gt;If you’ve searched for &lt;strong&gt;useDarkSwitch&lt;/strong&gt; on Google and struggled to find it, you’re not alone. Visibility issues can stem from:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;New Package Syndrome:&lt;/strong&gt; New packages often take time to rank on search engines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Competition:&lt;/strong&gt; Keywords like "dark mode" and "React hooks" are highly competitive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content Gaps:&lt;/strong&gt; Lack of optimized articles, tutorials, and backlinks.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to Improve Visibility
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Write Tutorials:&lt;/strong&gt; Publish how-to guides and case studies using useDarkSwitch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage Social Media:&lt;/strong&gt; Share your work on platforms like Twitter, LinkedIn, and Reddit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Engage Communities:&lt;/strong&gt; Post on developer forums like Stack Overflow and Dev.to.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate:&lt;/strong&gt; Partner with tech bloggers and influencers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advanced Features
&lt;/h2&gt;

&lt;p&gt;Want more power? useDarkSwitch isn’t just a toggle—it’s a gateway to deeper customization:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Custom Hooks:&lt;/strong&gt; Extend the functionality to support complex use cases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Theming Libraries:&lt;/strong&gt; Integrate with tools like Tailwind CSS or Material-UI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Listeners:&lt;/strong&gt; React to changes in real-time with seamless animations.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useDarkSwitch&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use-dark-switch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDarkMode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleDarkMode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDarkSwitch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;initialMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Theme switched to: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`app-container &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;isDarkMode&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Custom&lt;/span&gt; &lt;span class="nx"&gt;Dark&lt;/span&gt; &lt;span class="nx"&gt;Mode&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/header&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggleDarkMode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Toggle&lt;/span&gt; &lt;span class="nx"&gt;Theme&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In an era where user experience reigns supreme, &lt;strong&gt;useDarkSwitch&lt;/strong&gt; offers a simple yet robust solution to implement dark mode in your applications. Its lightweight, customizable nature ensures that you can adapt it to any project without compromising performance.&lt;/p&gt;

&lt;p&gt;Ready to enhance your application? &lt;a href="https://www.npmjs.com/package/use-dark-switch" rel="noopener noreferrer"&gt;Get started with useDarkSwitch today&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;You can read the docs on &lt;a href="https://github.com/nierowheezy/use-dark-switch/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; for more examples&lt;/p&gt;

&lt;p&gt;Let your users toggle effortlessly, and watch your app light up (or dim down) with brilliance.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>react</category>
      <category>usedarkswitch</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Mastering TypeScript with React: A Step-by-Step Guide</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Thu, 19 Sep 2024 15:36:44 +0000</pubDate>
      <link>https://dev.to/niero/mastering-typescript-with-react-a-step-by-step-guide-286l</link>
      <guid>https://dev.to/niero/mastering-typescript-with-react-a-step-by-step-guide-286l</guid>
      <description>&lt;h2&gt;
  
  
  🙋🏻‍♀️ Introduction
&lt;/h2&gt;

&lt;p&gt;TypeScript adds static typing to JavaScript, which helps catch potential bugs before they even run. When paired with React, TypeScript enhances your components by enforcing type safety. In this article, we'll walk through the essential concepts for using TypeScript with React.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚛️ How to Use TypeScript with React?
&lt;/h2&gt;

&lt;p&gt;First, you need to install TypeScript in a React project. If you're starting from scratch, create a new React app with TypeScript enabled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app my-app &lt;span class="nt"&gt;--template&lt;/span&gt; typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For an existing project, you can add TypeScript by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;typescript @types/react @types/react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can start using &lt;code&gt;.tsx&lt;/code&gt; files instead of &lt;code&gt;.js&lt;/code&gt; or &lt;code&gt;.jsx&lt;/code&gt;, and your React components will benefit from TypeScript’s features.&lt;/p&gt;




&lt;h2&gt;
  
  
  Types for React Component Props
&lt;/h2&gt;

&lt;p&gt;When you’re defining a component in React, you can specify the types for its props to make the usage of the component clearer and safer. Here’s a basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;UserProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserCard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;UserProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; years old&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;UserCard&lt;/code&gt; expects two props: &lt;code&gt;name&lt;/code&gt; (a string) and &lt;code&gt;age&lt;/code&gt; (a number). If you try to pass incorrect types, TypeScript will show an error.&lt;/p&gt;




&lt;h2&gt;
  
  
  ReactNode Vs ReactElement
&lt;/h2&gt;

&lt;p&gt;You might wonder when to use &lt;code&gt;ReactNode&lt;/code&gt; or &lt;code&gt;ReactElement&lt;/code&gt; for typing React components.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ReactNode&lt;/strong&gt;: Represents anything that can be rendered by React. This includes strings, numbers, JSX, arrays, and &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ReactElement&lt;/strong&gt;: Refers to an actual React element, which is more specific and doesn’t cover strings or &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;CardProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ReactNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;CardProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, World!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ReactNode&lt;/code&gt; is used here because &lt;code&gt;children&lt;/code&gt; can be any renderable element, not just React elements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Type Vs Interface
&lt;/h2&gt;

&lt;p&gt;When defining the shape of props or other objects, both &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;interface&lt;/code&gt; can be used. So, what’s the difference?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Type&lt;/strong&gt;: Best for creating union types or more complex combinations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interface&lt;/strong&gt;: Often better when you plan to extend or implement additional types.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s a comparison:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Using type&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Using interface&lt;/span&gt;
&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;LinkProps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;href&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;openInNewTab&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While both are similar, &lt;code&gt;interface&lt;/code&gt; can be extended more naturally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;IconButtonProps&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How to Type Props with TypeScript?
&lt;/h2&gt;

&lt;p&gt;To type props for a component, declare a &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;interface&lt;/code&gt; and pass it as the type annotation for the component's props.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;AlertProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;warning&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;info&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Alert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;severity&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;AlertProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`alert &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How to Type Functional Component Props?
&lt;/h2&gt;

&lt;p&gt;To type a functional component's props, you can use &lt;code&gt;React.FC&amp;lt;Props&amp;gt;&lt;/code&gt; or declare the props explicitly. While &lt;code&gt;React.FC&lt;/code&gt; was commonly used, now many prefer explicit types.&lt;/p&gt;

&lt;p&gt;Here’s an example using explicit types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;BadgeProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Badge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;BadgeProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;Badge&lt;/code&gt; has two props, &lt;code&gt;text&lt;/code&gt; and &lt;code&gt;color&lt;/code&gt;, both typed as strings.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⛓ React Hooks with TypeScript
&lt;/h2&gt;

&lt;p&gt;React hooks can also be typed in TypeScript to ensure type safety for the state and effect logic in your components.&lt;/p&gt;

&lt;p&gt;Here’s how to use &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; with TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Count is: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Increment&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;useState&lt;/code&gt; hook is typed to ensure &lt;code&gt;count&lt;/code&gt; is always a number, and &lt;code&gt;useEffect&lt;/code&gt; logs the current count whenever it changes.&lt;/p&gt;




&lt;p&gt;By following these best practices, you’ll be able to harness the full potential of TypeScript in your React applications, leading to more robust, maintainable code.&lt;/p&gt;

&lt;p&gt;And before you go, if you’re also working with SQL, check out our &lt;a href="https://github.com/Nierowheezy/sql-cheatsheet" rel="noopener noreferrer"&gt;Ultimate SQL Cheatsheet&lt;/a&gt; to improve your SQL skills with both basic and advanced queries!&lt;/p&gt;




</description>
      <category>typescript</category>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>20 Essential Libraries To Know if You Work with React</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Thu, 19 Sep 2024 14:34:32 +0000</pubDate>
      <link>https://dev.to/niero/20-essential-libraries-to-know-if-you-work-with-react-1o90</link>
      <guid>https://dev.to/niero/20-essential-libraries-to-know-if-you-work-with-react-1o90</guid>
      <description>&lt;p&gt;React has become the go-to library for building user interfaces, thanks to its flexibility, simplicity, and massive ecosystem of libraries. However, if you want to get the most out of React and enhance your development speed, there are several essential libraries you should integrate into your workflow. Whether you're focusing on state management, routing, or form validation, these libraries will make your life as a React developer much easier.&lt;/p&gt;

&lt;p&gt;In this article, we’ll cover 20 key libraries that can supercharge your React applications, complete with code samples and examples.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1. React Router&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Navigating between different pages in a React app is seamless with React Router. It allows you to build single-page applications with dynamic routing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Switch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;2. Axios&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For making HTTP requests, &lt;strong&gt;Axios&lt;/strong&gt; provides an easy-to-use API and supports features like interceptors, request cancelation, and transforming request/response data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;FetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;3. React Hook Form&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Forms can get complicated, but &lt;strong&gt;React Hook Form&lt;/strong&gt; simplifies form handling in React. It integrates with native HTML forms, providing better performance and reduced re-renders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-hook-form
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useForm&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-hook-form&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"First Name"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lastName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Last Name"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;4. Styled Components&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you love writing CSS but want to manage it within your React components, &lt;strong&gt;Styled Components&lt;/strong&gt; lets you do just that. You can write actual CSS syntax while keeping styles scoped to components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  background: palevioletred;
  color: white;
  font-size: 1em;
  padding: 0.25em 1em;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click Me!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;5. React Query&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For managing server-side data, &lt;strong&gt;React Query&lt;/strong&gt; is an excellent choice. It simplifies data fetching, caching, and syncing without all the boilerplate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-query&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Error loading data&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;6. Recoil&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Recoil&lt;/strong&gt; is an experimental state management library for React that simplifies state management by leveraging React’s hooks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;recoil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRecoilState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;recoil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;textState&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;TextInput&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRecoilState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;textState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;7. Framer Motion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For animations, &lt;strong&gt;Framer Motion&lt;/strong&gt; is an amazing library that provides powerful animations while keeping them declarative and easy to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;framer-motion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;motion&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;framer-motion&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
      &lt;span class="na"&gt;animate&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;8. Emotion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Like Styled Components, &lt;strong&gt;Emotion&lt;/strong&gt; is a powerful library for styling components in React. It allows writing CSS with JavaScript without any additional setup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @emotion/react @emotion/styled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @jsxImportSource @emotion/react */&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;css&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@emotion/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;css&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: lightblue;
  font-size: 24px;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;css&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, World!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;9. React Bootstrap&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;React Bootstrap&lt;/strong&gt; is a React wrapper for the Bootstrap framework, allowing you to use Bootstrap components without relying on jQuery.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-bootstrap bootstrap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-bootstrap&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bootstrap/dist/css/bootstrap.min.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Primary Button&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;10. Formik&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Another great form handling library is &lt;strong&gt;Formik&lt;/strong&gt;, which simplifies forms in React by handling form state, validation, and submission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;formik
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Formik&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Form&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;formik&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Formik&lt;/span&gt;
      &lt;span class="na"&gt;initialValues&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Field&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Enter your name"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Formik&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;SQL Enthusiasts, Don’t Miss Out&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you're also working with databases and need a handy reference for SQL, check out my &lt;a href="https://github.com/Nierowheezy/sql-cheatsheet" rel="noopener noreferrer"&gt;SQL Cheatsheet on GitHub&lt;/a&gt;. This cheatsheet covers both basic and advanced SQL queries, perfect for leveling up your database skills. Fork, clone, and star the repo to keep it available as your go-to SQL reference.&lt;/p&gt;




&lt;p&gt;I'll continue the list in a follow-up article to avoid overwhelming this one, but these 10 libraries are a great start for building more efficient and powerful React applications.&lt;/p&gt;

&lt;p&gt;Be sure to experiment with these libraries, as each provides unique capabilities that can save you time and effort. Keep coding, and happy React-ing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Master SQL Like a Pro: The Ultimate SQL Cheatsheet</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Thu, 19 Sep 2024 09:32:56 +0000</pubDate>
      <link>https://dev.to/niero/master-sql-like-a-pro-the-ultimate-sql-cheatsheet-l11</link>
      <guid>https://dev.to/niero/master-sql-like-a-pro-the-ultimate-sql-cheatsheet-l11</guid>
      <description>&lt;p&gt;Structured Query Language, commonly known as SQL, is the backbone of database management. From retrieving data to performing complex operations, SQL powers almost all databases, making it one of the most vital skills in a developer’s toolkit.&lt;/p&gt;

&lt;p&gt;Whether you’re new to SQL or a seasoned database admin, having a handy reference guide can save you countless hours of trial and error. That's why I created the &lt;strong&gt;Ultimate SQL Cheatsheet&lt;/strong&gt;, which covers both basic and advanced SQL techniques, designed to help you master SQL and maximize your efficiency. In this article, I’ll share a sneak peek of what you can expect inside the cheatsheet. If you’re ready to dive deeper, you can fork, clone, or star the repo for an in-depth look!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get the full cheatsheet here&lt;/strong&gt;: &lt;a href="https://github.com/Nierowheezy/sql-cheatsheet" rel="noopener noreferrer"&gt;Ultimate SQL Cheatsheet on GitHub&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;What is SQL?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;SQL (Structured Query Language) is a standardized programming language used to manage and manipulate relational databases. From querying data to defining structures, SQL allows developers to interact with the database in powerful ways. Whether you’re working with MySQL, PostgreSQL, or SQL Server, SQL syntax remains largely consistent across platforms.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Basics of SQL&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s start with some core commands that every beginner should know. These commands allow you to retrieve data, filter it, and manage it efficiently.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;SELECT Statement&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;One of the most fundamental SQL queries, the &lt;code&gt;SELECT&lt;/code&gt; statement retrieves data from the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This basic query pulls the &lt;code&gt;first_name&lt;/code&gt; and &lt;code&gt;last_name&lt;/code&gt; columns from the &lt;code&gt;employees&lt;/code&gt; table. Simple, but very powerful.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;WHERE Clause&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Use the &lt;code&gt;WHERE&lt;/code&gt; clause to filter the data returned by the &lt;code&gt;SELECT&lt;/code&gt; statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Sales'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query will return the names of employees who work in the Sales department.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;JOIN Operations&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Joins are essential for working with multiple tables in a relational database. An &lt;code&gt;INNER JOIN&lt;/code&gt; returns rows that have matching values in both tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; 
&lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query matches orders to customers and retrieves their names alongside the order IDs.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced SQL Techniques&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once you’ve mastered the basics, SQL offers more powerful and complex functionalities. These advanced techniques allow you to manipulate data more efficiently and handle large datasets with precision.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Subqueries&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Subqueries allow you to execute a query inside another query, giving you more flexibility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;departments&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;department_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'HR'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this query, a subquery is used to fetch the &lt;code&gt;department_id&lt;/code&gt; of the HR department, which is then passed to the main query.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Common Table Expressions (CTEs)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;CTEs simplify complex queries by creating temporary result sets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;SalesData&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;TotalSales&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;TotalSales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;SalesData&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;TotalSales&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;50000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;SalesData&lt;/code&gt; is a CTE used to calculate the total sales for each employee, and then filter those whose total sales exceed 50,000.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Window Functions&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Window functions are used for tasks like running totals, rankings, and moving averages without collapsing data into groups.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
       &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query ranks employees by salary within each department without aggregating the data.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;Performance Optimization Tips&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Efficient SQL queries are essential for handling large datasets. Indexes, query execution plans, and avoiding unnecessary &lt;code&gt;SELECT *&lt;/code&gt; are a few ways to optimize query performance.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Fork, Clone, and Star the Ultimate SQL Cheatsheet&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Ultimate SQL Cheatsheet&lt;/strong&gt; is packed with more examples and use cases like the ones above. Whether you need a quick reference for everyday queries or want to deepen your SQL expertise, this repository has you covered.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fork&lt;/strong&gt; the repo to customize your own version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clone&lt;/strong&gt; it to keep it available offline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Star&lt;/strong&gt; it to show your support and help others discover this helpful resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Head over to the full repository here: &lt;a href="https://github.com/Nierowheezy/sql-cheatsheet" rel="noopener noreferrer"&gt;Ultimate SQL Cheatsheet on GitHub&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;In Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;SQL is an essential tool for working with databases, and mastering it can open up countless opportunities in your development journey. The &lt;strong&gt;Ultimate SQL Cheatsheet&lt;/strong&gt; is designed to help you along the way, whether you’re just starting or you’re diving into advanced SQL techniques. &lt;/p&gt;

&lt;p&gt;Don’t forget to fork, clone, and star the repo to keep it handy!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://github.com/Nierowheezy/sql-cheatsheet" rel="noopener noreferrer"&gt;Ultimate SQL Cheatsheet on GitHub&lt;/a&gt;
&lt;/h2&gt;

</description>
    </item>
    <item>
      <title>Generating Unique Random Numbers in JavaScript Using Sets</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Thu, 29 Aug 2024 16:47:22 +0000</pubDate>
      <link>https://dev.to/niero/generating-unique-random-numbers-in-javascript-using-sets-2dcd</link>
      <guid>https://dev.to/niero/generating-unique-random-numbers-in-javascript-using-sets-2dcd</guid>
      <description>&lt;p&gt;When working with JavaScript, you may often need to generate random numbers for various purposes, such as creating unique identifiers, simulating data, or adding unpredictability to an application. However, ensuring that these numbers are unique can be a bit tricky, especially if you need a large set of them. This is where JavaScript's &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; object comes in handy. In this article, we'll explore how to generate unique random numbers using &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; and why it's an effective approach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use Sets for Unique Random Numbers?&lt;/strong&gt;&lt;br&gt;
In JavaScript, a &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; is a collection of values that automatically removes duplicates. This makes it an ideal tool for generating unique random numbers. Unlike arrays, which can contain duplicate values and require additional checks to enforce uniqueness, Set inherently ensures that all elements are unique. This not only simplifies the code but also enhances performance when generating large sets of random numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-Step Guide to Generating Unique Random Numbers&lt;br&gt;
Let's walk through how to generate a **&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; of unique random numbers using JavaScript.**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initialize the Set Begin by creating a new Set to store your unique random numbers.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const uniqueNumbers = new Set();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Generate Random Numbers Use a loop to generate random numbers and add them to the Set. The loop continues until the desired number of unique random numbers is reached.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (uniqueNumbers.size &amp;lt; 10) {  // Adjust the number 10 to your desired count
    const randomNumber = Math.floor(Math.random() * 100) + 1; // Generates numbers between 1 and 100
    uniqueNumbers.add(randomNumber);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Math.random()&lt;/code&gt;&lt;/strong&gt; generates a random floating-point number between 0 (inclusive) and 1 (exclusive).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Math.floor()&lt;/code&gt;&lt;/strong&gt; rounds the number down to the nearest integer.&lt;/li&gt;
&lt;li&gt;Multiplying by 100 and adding 1 shifts the range to 1-100.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Convert the Set to an Array&lt;/strong&gt; Although &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; is a great tool for ensuring uniqueness, you might want to work with an array afterward. You can easily convert the &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; back into an array using the &lt;strong&gt;&lt;code&gt;Array.from()&lt;/code&gt;&lt;/strong&gt; method or the spread operator.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const uniqueArray = Array.from(uniqueNumbers);
// Or using spread operator
// const uniqueArray = [...uniqueNumbers];
console.log(uniqueArray);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why Not Use an Array?&lt;/strong&gt;&lt;br&gt;
You might wonder why we don't simply use an array with additional checks to avoid duplicates. While it's possible to use arrays, the process would involve checking if each newly generated number is already in the array, which could become inefficient with larger datasets. Using a &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; automatically handles duplicates, making the code cleaner and faster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-World Applications&lt;/strong&gt;&lt;br&gt;
Generating unique random numbers is a common task in various scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Games&lt;/strong&gt;: Creating unique IDs for players or generating randomized levels.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simulations&lt;/strong&gt;: Modeling random events without repetition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Sampling&lt;/strong&gt;: Selecting unique random samples from a larger dataset.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Performance Considerations&lt;/strong&gt;&lt;br&gt;
While using Set is generally efficient, it's important to note that the performance could be affected by the range of numbers and the required size of the unique set. For very large ranges or when you need a high quantity of unique numbers, you may need to consider additional optimization strategies or use specialized libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Using JavaScript's &lt;strong&gt;&lt;code&gt;Set&lt;/code&gt;&lt;/strong&gt; to generate unique random numbers is a simple yet powerful technique that eliminates the need for manual checks for duplicates. Whether you're building a game, running simulations, or sampling data, this method provides a clean and efficient way to ensure the uniqueness of your random numbers. Give it a try in your next project, and enjoy the benefits of cleaner code and faster execution!&lt;/p&gt;

&lt;p&gt;If you found this guide helpful, be sure to like and share your thoughts below! 👇&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering Express.js: A Beginner’s Roadmap to Backend Development</title>
      <dc:creator>Olaniyi Olabode</dc:creator>
      <pubDate>Thu, 29 Aug 2024 11:36:06 +0000</pubDate>
      <link>https://dev.to/niero/mastering-expressjs-a-beginners-roadmap-to-backend-development-4g49</link>
      <guid>https://dev.to/niero/mastering-expressjs-a-beginners-roadmap-to-backend-development-4g49</guid>
      <description>&lt;p&gt;&lt;strong&gt;Express.js Essentials: A Beginner’s Guide&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Welcome to the ultimate guide on Express.js! Think of this as your go-to resource for everything you need to kickstart your journey with backend development using Express.js.&lt;/p&gt;

&lt;p&gt;Express.js stands tall as one of the most popular web frameworks for Node.js. Its simplicity and flexibility make it the backbone of countless applications, from tiny APIs to vast web services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What You'll Learn:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setting Up an Express.js Application&lt;/li&gt;
&lt;li&gt;Routing in Express.js&lt;/li&gt;
&lt;li&gt;Middleware in Express.js&lt;/li&gt;
&lt;li&gt;Handling Requests and Responses&lt;/li&gt;
&lt;li&gt;Serving Static Files&lt;/li&gt;
&lt;li&gt;Template Engines and Rendering Views&lt;/li&gt;
&lt;li&gt;Authentication and Security&lt;/li&gt;
&lt;li&gt;Environment Variables and Configuration&lt;/li&gt;
&lt;li&gt;Working with Databases&lt;/li&gt;
&lt;li&gt;Best Practices and Common Patterns&lt;/li&gt;
&lt;li&gt;Ready to dive in? Let’s get started! 🚀&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Getting Started with Express.js&lt;/strong&gt;&lt;br&gt;
Kicking off with Express.js is simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Node.js: Ensure Node.js is up and running.&lt;/li&gt;
&lt;li&gt;Create a New Project: Use npm init -y to generate a package.json file.Add Express.js: Install Express.js with npm i express.&lt;/li&gt;
&lt;li&gt;Initialize Your Application: Set up your Express app in an app.js or index.js file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const express = require('express');
    const app = express();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Understanding Routing in Express.js&lt;/strong&gt;&lt;br&gt;
Routing forms the core of any Express.js application. Express makes it easy to define routes:&lt;/p&gt;

&lt;p&gt;Basic Routing: Manage GET, POST, PUT, and DELETE requests. Dynamic Route Parameters: Extract variable data, such as user IDs, directly from URLs. Handling Query Parameters: Work with data appended to URLs via query strings.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    `// REQUEST HANDLERS
    app.get('/', (req, res) =&amp;gt; {
        res.send("Hello, reader!"); // Client-side
        console.log("Hello, reader!"); // Server-side
    });`


    `// ROUTE PARAMETERS
    app.get('/users/:id', (req, res) =&amp;gt; {
      const userId = req.params.id;
      res.send(`User ID: ${userId}`);
    });`


    `// QUERY PARAMETERS
    app.get('/search', (req, res) =&amp;gt; {
      const searchTerm = req.query.term;
      const limit = req.query.limit;
      res.send(`Searching for "${searchTerm}" with a limit of ${limit} results.`);
    });`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. Exploring Middleware Functions in Express.js&lt;/strong&gt;&lt;br&gt;
Middleware acts as checkpoints in the request-response cycle, essential for request modification, response handling, and control flow management.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const logRequest = (req, res, next) =&amp;gt; {
      console.log(`Request made to ${req.url}`);
      next(); // Hand control to the next middleware
    };


    // Implement logRequest as middleware
    app.get('/', logRequest, (req, res) =&amp;gt; {
      res.send('Home Page');
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;4. Managing Requests and Responses&lt;/strong&gt;&lt;br&gt;
Express offers a streamlined approach to managing HTTP requests and crafting responses:&lt;/p&gt;

&lt;p&gt;Accessing Request Data: Easily retrieve client-sent data.&lt;br&gt;
Sending Responses: Use res.send(), res.json(), or res.render() to send data back.&lt;br&gt;
Method Chaining: Combine methods like res.status().json() for more concise code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    app.get('/example', (req, res) =&amp;gt; {
      res.status(200).json({ message: 'Success!' });
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;5. Serving Static Content&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Simplify the process of serving static files, like HTML, CSS, and JavaScript:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    app.use(express.static('public')); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;// Serve files directly from the 'public' directory 💡 Files in the&lt;br&gt;
public directory are accessible to all clients.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;6. Integrating Template Engines and Rendering Dynamic Views&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Express smoothly integrates with template engines like EJS, Pug, and Handlebars to create dynamic web pages:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Setting Up a Template Engine: Begin with EJS for an intuitive&lt;br&gt;
experience. Rendering Dynamic Content: Use res.render() to inject data&lt;br&gt;
into views.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    app.set('view engine', 'ejs');
    app.get('/home', (req, res) =&amp;gt; {
      res.render('home', { title: 'Home Page' });
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;7. Implementing Authentication and Security&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Security is paramount in web development, and Express provides robust tools:&lt;/p&gt;

&lt;p&gt;Authentication Methods: Implement JWT or OAuth for secure user authentication.&lt;br&gt;
Security Middleware: Utilize helmet for security headers, cors for cross-origin requests, and rate limiting to prevent DDoS attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Utilizing Environment Variables and Configuration Settings&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Securely manage sensitive data and app configuration with environment variables:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    require('dotenv').config();
    const PORT = process.env.PORT || 3000;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;9. Connecting to Databases&lt;/strong&gt;&lt;br&gt;
Express can interface with various databases, whether NoSQL or SQL:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;MongoDB Integration: Manage MongoDB with Mongoose. Relational&lt;br&gt;
Databases: Leverage Sequelize or TypeORM for SQL databases. Note: This&lt;br&gt;
topic warrants a detailed, standalone article.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;10. Adopting Best Practices and Design Patterns&lt;br&gt;
Follow these guidelines to build scalable and maintainable Express applications:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modularize Your Code: Use express.Router to create manageable, modular routes.&lt;br&gt;
Async/Await for Asynchronous Code: Handle async operations efficiently to avoid callback hell.&lt;br&gt;
Error Handling: Pass errors to dedicated middleware using next(err).&lt;/p&gt;

&lt;p&gt;If you found this guide helpful, be sure to like and share your thoughts below! 👇&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
