<?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: Erlin Banegas</title>
    <description>The latest articles on DEV Community by Erlin Banegas (@esbanegas).</description>
    <link>https://dev.to/esbanegas</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%2F2979531%2Fe968d89d-7197-4575-8cfc-83e2cb2dec30.png</url>
      <title>DEV Community: Erlin Banegas</title>
      <link>https://dev.to/esbanegas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/esbanegas"/>
    <language>en</language>
    <item>
      <title>Master the Basics Before You Trust the AI</title>
      <dc:creator>Erlin Banegas</dc:creator>
      <pubDate>Wed, 21 May 2025 05:34:35 +0000</pubDate>
      <link>https://dev.to/esbanegas/master-the-basics-before-you-trust-the-ai-576k</link>
      <guid>https://dev.to/esbanegas/master-the-basics-before-you-trust-the-ai-576k</guid>
      <description>&lt;p&gt;Are you just starting out in programming, or have you been at it for a while but still struggle with the fundamentals?&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%2F808geggalp53cl89nua4.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%2F808geggalp53cl89nua4.png" alt="Don’t learn to depend — learn to understand." width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take a moment to pause and reflect: what are you really aiming for?&lt;br&gt;
Don't try to learn everything at once. Choose one language and focus on learning its fundamentals. These are the pillars every good programmer should know — and unlike frameworks or tools, fundamentals don’t change.&lt;/p&gt;

&lt;p&gt;Fundamentals are not just the foundation — they define who you are as a developer. They prepare you to understand the logic behind problems and help you build solutions to the real-world challenges we often face in programming.&lt;/p&gt;

&lt;p&gt;You’ve probably heard the phrase: &lt;em&gt;“Before you run, learn to walk.”&lt;/em&gt;&lt;br&gt;
These days, there’s a rush to learn everything fast. People rely heavily on AI, thinking it can do it all — even replace them. But here’s the truth: AI is just a tool. You can use it to support your learning, but don’t depend on it until you understand the basics.&lt;/p&gt;

&lt;p&gt;Learning the fundamentals will empower you to tell the AI things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“That’s not what I asked for.”&lt;/li&gt;
&lt;li&gt;“Use this approach instead.”&lt;/li&gt;
&lt;li&gt;“Why are you doing it that way?”&lt;/li&gt;
&lt;li&gt;“Apply this design pattern.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without that knowledge, you won’t know if the code it gives you is wrong — and &lt;strong&gt;how will you fix something you don’t understand?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Before you run, learn to walk.&lt;/em&gt;&lt;br&gt;
Don’t skip the fundamentals just because AI seems to make things easier. Learn the core principles of the language you're using. Most of the time, AI-generated code needs to be corrected. If you don’t know the basics, how will you even notice what’s wrong?&lt;/p&gt;

&lt;p&gt;Final Tip:&lt;br&gt;
Start with the official documentation of the language you're learning. Build the habit of researching on your own. Read books — physical or digital, it doesn’t matter. What matters is that you develop the skill of &lt;strong&gt;independent learning&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;The developers who adapt are the ones who thrive.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Custom Hooks – useKeyPress</title>
      <dc:creator>Erlin Banegas</dc:creator>
      <pubDate>Fri, 09 May 2025 04:35:46 +0000</pubDate>
      <link>https://dev.to/esbanegas/custom-hooks-usekeypress-3d5g</link>
      <guid>https://dev.to/esbanegas/custom-hooks-usekeypress-3d5g</guid>
      <description>&lt;p&gt;Adding keyboard shortcuts to a web application not only improves the user experience, but also makes certain tasks much faster and more intuitive.&lt;/p&gt;

&lt;p&gt;The custom hook useKeyPress allows you to react to combinations like &lt;strong&gt;⌘ + ArrowUp&lt;/strong&gt; or single keys like F2, in a declarative and reusable way.&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%2F7628tmnuh054n9rwli6i.gif" 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%2F7628tmnuh054n9rwli6i.gif" alt="Image description" width="598" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A demo showing &lt;code&gt;⌘ + ArrowUp&lt;/code&gt;, &lt;code&gt;⌘ + ArrowDown&lt;/code&gt;, and &lt;code&gt;F2&lt;/code&gt; controlling a counter.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What does useKeyPress do?
&lt;/h3&gt;

&lt;p&gt;This hook lets you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Listen to multiple key combinations from an array, like ["⌘ + ArrowUp", "F2"].&lt;/li&gt;
&lt;li&gt;Receive the main key pressed as an argument (e.g., "ArrowUp", "F2").&lt;/li&gt;
&lt;li&gt;Use a single handler function to manage multiple shortcuts easily with if or switch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example: keyboard-controlled counter
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";
import { useKeyPress } from "../core/hooks";

export const KeyPressComponent = () =&amp;gt; {
  const [counter, setCounter] = useState(0);

  useKeyPress(["⌘ + ArrowDown", "⌘ + ArrowUp", "F2"], (key: string) =&amp;gt; {
    if (key === "ArrowDown") 
        setCounter((prev) =&amp;gt; prev - 1);

    if (key === "ArrowUp") 
        setCounter((prev) =&amp;gt; prev + 1);

    if (key === "F2") 
        setCounter(0);
  });

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Key Press Example&amp;lt;/h1&amp;gt;
      &amp;lt;strong&amp;gt;{counter}&amp;lt;/strong&amp;gt;
      &amp;lt;p&amp;gt;
        Press &amp;lt;em&amp;gt;⌘ + ArrowUp&amp;lt;/em&amp;gt; to increase the counter
      &amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;
        Press &amp;lt;em&amp;gt;⌘ + ArrowDown&amp;lt;/em&amp;gt; to decrease the counter
      &amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Press F2 to reset the counter&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  How does it work internally?
&lt;/h3&gt;

&lt;p&gt;Under the hood, useKeyPress listens for global keyboard events, normalizes combinations (e.g., "⌘ + ArrowUp" becomes "meta+arrowup"), and runs your callback only when an exact match is detected. You only get the main key in the callback ("ArrowUp", "F2", etc.), which keeps your component logic clean.&lt;/p&gt;

&lt;p&gt;Here’s a full example of the hook implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useEffect } from "react";

const useKeyPress = (keys: string[], callback: (key: string) =&amp;gt; void) =&amp;gt; {
  useEffect(() =&amp;gt; {
    const handleKeyDown = (event: KeyboardEvent) =&amp;gt; {
      const pressedKey = event.key.toLowerCase();

      const normalizedKeys = keys.map((key) =&amp;gt;
        key
          .toLowerCase()
          .split(" + ")
          .map((k) =&amp;gt; k.trim())
      );

      const modifiers = {
        control: event.ctrlKey,
        shift: event.shiftKey,
        alt: event.altKey,
        meta: event.metaKey,
        "⌘": event.ctrlKey,
        ctrl: event.ctrlKey,
      };

      const modifierKeys = [
        "control",
        "shift",
        "alt",
        "meta",
        "⌘",
        "ctrl",
      ] as const;

      for (const combination of normalizedKeys) {
        const requiredModifiers = combination.filter((key) =&amp;gt;
          modifierKeys.includes(key as (typeof modifierKeys)[number])
        );
        const requiredKeys = combination.filter(
          (key) =&amp;gt; !modifierKeys.includes(key as (typeof modifierKeys)[number])
        );

        const allModifiersMatch = requiredModifiers.every(
          (mod) =&amp;gt; modifiers[mod as keyof typeof modifiers]
        );

        const keyMatch = requiredKeys.includes(pressedKey);

        if (keyMatch &amp;amp;&amp;amp; allModifiersMatch) {
          event.preventDefault();
          callback(event.key);
          return;
        }
      }
    };

    document.addEventListener("keydown", handleKeyDown, { capture: true });

    return () =&amp;gt; {
      document.removeEventListener("keydown", handleKeyDown, { capture: true });
    };
  }, [keys, callback]);
};

export default useKeyPress;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✅ Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Clear syntax: define multiple combinations in an array.&lt;/li&gt;
&lt;li&gt;✅ Clean-up included: automatically removes the listener.&lt;/li&gt;
&lt;li&gt;✅ Flexible: works across different platforms (Windows, macOS).&lt;/li&gt;
&lt;li&gt;✅ Declarative: avoids manual DOM event handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🧠 Final thoughts
&lt;/h3&gt;

&lt;p&gt;Handling keyboard shortcuts doesn’t have to be messy. With useKeyPress, you can keep your components clean while adding power-user features that scale well.&lt;/p&gt;

&lt;p&gt;Want to extend it?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ignore events when inside an &lt;/li&gt;
&lt;li&gt;Add debounce or throttle&lt;/li&gt;
&lt;li&gt;Support dynamic combos via state&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🙌 Thanks for reading
&lt;/h2&gt;

&lt;p&gt;Thanks for reading this post — I hope it was helpful!&lt;/p&gt;

&lt;p&gt;Feel free to leave a comment or suggestion below.&lt;br&gt;
You're welcome to try, adapt, and improve the useKeyPress hook to fit your own use case.&lt;/p&gt;

&lt;p&gt;Happy coding! 🎯&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactjsdevelopment</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Rest Client - Fetch</title>
      <dc:creator>Erlin Banegas</dc:creator>
      <pubDate>Sun, 04 May 2025 09:06:24 +0000</pubDate>
      <link>https://dev.to/esbanegas/rest-client-fetch-1l3k</link>
      <guid>https://dev.to/esbanegas/rest-client-fetch-1l3k</guid>
      <description>&lt;h2&gt;
  
  
  Learn How to Use Fetch and Create a Reusable Rest Client in JavaScript
&lt;/h2&gt;

&lt;p&gt;In this blog post, we’ll explore the basics of the Fetch API and how to create a reusable RestClient class to simplify your HTTP requests in web applications.&lt;/p&gt;

&lt;p&gt;Table of Contents&lt;/p&gt;

&lt;p&gt;What is Fetch?&lt;br&gt;
Using Fetch: Examples&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET Request&lt;/li&gt;
&lt;li&gt;POST Request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reusable RestClient Class&lt;br&gt;
Using RestClient in React&lt;/p&gt;
&lt;h3&gt;
  
  
  🛰️ What is Fetch? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The Fetch API is a modern JavaScript interface used to make HTTP requests to servers. It returns a Promise, which can be handled with async/await or .then() syntax.&lt;/p&gt;

&lt;p&gt;To learn more about Promises, check the MDN documentation.&lt;/p&gt;
&lt;h3&gt;
  
  
  🚀 Using Fetch: Examples &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;✅ GET Request &lt;a&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response =&amp;gt; response.json())
  .then(json =&amp;gt; console.log(json));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Response:&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
  "userId": 1,&lt;br&gt;
  "id": 1,&lt;br&gt;
  "title": "delectus aut autem",&lt;br&gt;
  "completed": false&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This makes a simple GET request and parses the JSON response.&lt;/p&gt;
&lt;h3&gt;
  
  
  📤 POST Request &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const request = {
  title: 'foo',
  body: 'bar',
  userId: 1,
};

fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  body: JSON.stringify(request),
  headers: {
    'Content-type': 'application/json; charset=UTF-8',
  },
})
  .then(response =&amp;gt; response.json())
  .then(json =&amp;gt; console.log(json));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;For POST, PUT, and DELETE, you must explicitly define the method, headers, and body as shown above.&lt;/p&gt;
&lt;h3&gt;
  
  
  🧰 Reusable RestClient Class &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To avoid repeating fetch() logic throughout the app, I’ve created a reusable RestClient class. It simplifies HTTP communication and promotes consistency across requests.&lt;/p&gt;

&lt;p&gt;✅ Features&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Supports GET, POST, PUT, and DELETE requests.&lt;/li&gt;
&lt;li&gt;Returns a standardized response object with helpful metadata.&lt;/li&gt;
&lt;li&gt;Maps common HTTP error codes to friendly messages (e.g., 401 → "Unauthorized").&lt;/li&gt;
&lt;li&gt;Supports optional request cancellation using AbortController.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  ⚙️ Environment Setup
&lt;/h4&gt;

&lt;p&gt;This project uses Vite + React with the following environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_BASE_API_URL=https://jsonplaceholder.typicode.com
VITE_API_VERSION=v1  # Optional
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧱 ApiResponse Interface
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface ApiResponse&amp;lt;T&amp;gt; {
  success: boolean;
  data: T | null;
  message: string;
  error?: unknown;
  statusCode?: number;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This interface defines the standard structure for all responses. Whether a request succeeds or fails, you can consistently check:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;success&lt;/code&gt;: if the request was successful&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;data&lt;/code&gt;: the returned payload&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;message&lt;/code&gt;: a user-friendly summary&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;statusCode&lt;/code&gt;and error: optional debugging info&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  🧪 Example: Testing RestClient with Abort Support &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s see a real-world React component using the httpGetAsync() method with cancellation support via AbortController.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const RestClientTest = () =&amp;gt; {
  const [controller, setController] = useState&amp;lt;AbortController | null&amp;gt;(null);

  useCommands(
    {
      actions: [
        {
          label: "Send",
          variant: "solid",
          onClick: async () =&amp;gt; {
            const newController = new AbortController();
            setController(newController);
            const res = await restClient.httpGetAsync(
              "/posts",
              undefined,
              newController
            );

            if (!res.success) {
              toast.warn(res.message);
              return;
            }

            console.log(res);
          },
        },
        {
          label: "Abort Controller",
          variant: "ghost",
          onClick: async () =&amp;gt; {
            controller?.abort();
          },
        },
      ],
    },
    [controller]
  );

  return &amp;lt;div&amp;gt;Rest Client Test&amp;lt;/div&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  📷 Example Output
&lt;/h4&gt;

&lt;p&gt;Here’s what you’ll see in the console after a successful request:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clicking "Send" starts an HTTP GET request using restClient.httpGetAsync().&lt;/li&gt;
&lt;/ol&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%2Fre887wheu0w4vu8lay70.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%2Fre887wheu0w4vu8lay70.png" alt="Successful Request" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🧪 Simulating a Slow Request
&lt;/h3&gt;

&lt;p&gt;To test the cancellation feature, you can simulate slow network conditions in your browser:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open DevTools → Network tab.&lt;/li&gt;
&lt;li&gt;Change the throttling to "Slow 3G".&lt;/li&gt;
&lt;li&gt;Click Send and then Abort Request quickly.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This cancels the in-progress HTTP request before the response arrives:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clicking "Send" starts an HTTP GET request using restClient.httpGetAsync().&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clicking "Abort Request" cancels the ongoing request using AbortController.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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%2Faxpsgv14m9qb60bkqk6w.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%2Faxpsgv14m9qb60bkqk6w.png" alt="AbortController" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Full Source Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/esbanegas/rest-client-fetch" rel="noopener noreferrer"&gt;GitHub Repo - RestClientFetch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading all the way through.&lt;br&gt;
I hope this implementation helps you write cleaner, more reusable, and easier-to-maintain code.&lt;br&gt;
See you in the next post! 🚀&lt;/p&gt;

</description>
      <category>api</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
