<?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: The Naija Debugger </title>
    <description>The latest articles on DEV Community by The Naija Debugger  (@naijadebugger).</description>
    <link>https://dev.to/naijadebugger</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%2F2884831%2F7f7f272a-99c7-4bec-813e-edf11c0069e9.jpg</url>
      <title>DEV Community: The Naija Debugger </title>
      <link>https://dev.to/naijadebugger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/naijadebugger"/>
    <language>en</language>
    <item>
      <title>Fetching API Data with TypeScript: Using Type Assertions</title>
      <dc:creator>The Naija Debugger </dc:creator>
      <pubDate>Mon, 19 Jan 2026 19:19:08 +0000</pubDate>
      <link>https://dev.to/naijadebugger/fetching-api-data-with-typescript-using-type-assertions-16db</link>
      <guid>https://dev.to/naijadebugger/fetching-api-data-with-typescript-using-type-assertions-16db</guid>
      <description>&lt;p&gt;Today, I dove deeper into TypeScript and explored how to safely fetch and use data from an API. Now I understand how TypeScript helps prevent bugs, improve developer experience, and makes code more maintainable.&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%2F829exh46qcxrojo77hrq.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%2F829exh46qcxrojo77hrq.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Understanding the Problem&lt;br&gt;
When we fetch data from an API in JavaScript, we usually do something like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const response = await fetch("https://randomuser.me/api/?results=3");&lt;br&gt;
const data = await response.json();&lt;br&gt;
console.log(data);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;JavaScript doesn't care about types. The code will run even if the API changes its structure or fields. But in TypeScript:&lt;br&gt;
response.json() returns any (or unknown depending on settings)&lt;br&gt;
TypeScript doesn't know the shape of the data, so we can't safely access nested properties without risking errors. This is where type assertions come in.&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%2Fvbl049e2ek5ht332x1ai.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%2Fvbl049e2ek5ht332x1ai.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The images above illustrate the JSON structure returned by the RandomUser API and the EscuelaJS Products API respectively, which I used to practice TypeScript type assertions and API data typing. As you can see the structure of the data they return differs.&lt;br&gt;
Using TypeScript Type Assertions&lt;br&gt;
Type assertions tell TypeScript: "I know the structure of this data better than you do."&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%2Ft635yk00xh23kvexanm2.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%2Ft635yk00xh23kvexanm2.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://typescriptworld.com/a-deep-dive-into-typescript-type-assertions-from-basics-to-advanced-patterns" rel="noopener noreferrer"&gt;https://typescriptworld.com/a-deep-dive-into-typescript-type-assertions-from-basics-to-advanced-patterns&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
`const data = await response.json();&lt;/p&gt;

&lt;p&gt;const users = data as unknown as {&lt;br&gt;
  results: {&lt;br&gt;
    name: { first: string; last: string };&lt;br&gt;
    email: string;&lt;br&gt;
    picture: { large: string };&lt;br&gt;
  }[];&lt;br&gt;
};`&lt;/p&gt;

&lt;p&gt;data is unkown after response.json()&lt;br&gt;
as unknown as {…} tells TS: "Treat data as an object with a results array containing this exact structure"&lt;br&gt;
This allows us to safely access nested properties like results[0].name.firstwithout TypeScript complaining.&lt;br&gt;
The double assertion (as unknown as) is sometimes needed when TypeScript is too conservative and refuses a direct conversion.&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%2Fc35ndrnakn5actalv6jz.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%2Fc35ndrnakn5actalv6jz.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mapping API Data to Your Own Types&lt;br&gt;
Even after asserting the type, I didn't want to expose the entire nested API structure in my app. So I mapped the data to my own simpler type:&lt;/p&gt;

&lt;p&gt;`export type User = {&lt;br&gt;
  name: string;&lt;br&gt;
  email: string;&lt;br&gt;
  picture: string;&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;return users.results.map(u =&amp;gt; ({&lt;br&gt;
  name: &lt;code&gt;${u.name.first} ${u.name.last}&lt;/code&gt;,&lt;br&gt;
  email: u.email,&lt;br&gt;
  picture: u.picture.large&lt;br&gt;
}));`&lt;/p&gt;

&lt;p&gt;Now, the rest of my app can safely work with a clean, predictable User[] array, with proper typing and autocomplete support.&lt;/p&gt;

&lt;p&gt;Why This Matters&lt;br&gt;
Through this exercise, I realized how TypeScript helps in several ways:&lt;br&gt;
Prevent runtime crashes: TS catches mistakes before the code runs&lt;br&gt;
Autocompletion / IntelliSense: helps write code faster with fewer typos&lt;br&gt;
Self-documenting code: types tell anyone reading the code exactly what data looks like&lt;br&gt;
Safe refactoring: if I rename a field or the API changes, TS will warn me&lt;/p&gt;

&lt;p&gt;Even small experiments like fetching users or products can teach you how typed async flows work in real projects.&lt;/p&gt;

&lt;p&gt;Key points &lt;br&gt;
TypeScript doesn't magically know API data, so we teach it using types or type assertions&lt;br&gt;
Mapping API data to our own types makes apps safer and easier to work with&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>webdev</category>
      <category>coding</category>
    </item>
    <item>
      <title>Building Bulletproof Dropdown Click Handling in React</title>
      <dc:creator>The Naija Debugger </dc:creator>
      <pubDate>Sat, 10 Jan 2026 08:25:28 +0000</pubDate>
      <link>https://dev.to/naijadebugger/building-bulletproof-dropdown-click-handling-in-react-19mh</link>
      <guid>https://dev.to/naijadebugger/building-bulletproof-dropdown-click-handling-in-react-19mh</guid>
      <description>&lt;p&gt;By using data attributes and .closest(), the click-handling logic becomes resilient to DOM changes and easier to maintain.&lt;/p&gt;

&lt;p&gt;It focuses on the data (filter.id) rather than the DOM structure, making the component more reliable and scalable.&lt;/p&gt;

&lt;p&gt;In React, avoid relying on DOM hierarchy for logic. I learnt this the hard back when I used parentElement for this. Use data attributes with .closest() for robust click handling.&lt;/p&gt;

&lt;p&gt;The core idea is to listen for clicks on the entire document, then determine whether a click happened inside or outside your dropdown.&lt;/p&gt;

&lt;p&gt;This approach is necessary because the dropdown doesn’t know when a user clicks elsewhere.The browser always bubbles clicks upward:&lt;/p&gt;

&lt;p&gt;button -&amp;gt; div -&amp;gt; body -&amp;gt; document.&lt;/p&gt;

&lt;p&gt;It works even if icons, labels, or nested elements change.&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%2Fep7p7pfa4x3naihxldvt.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%2Fep7p7pfa4x3naihxldvt.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&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%2Fp5ditogm0uwhlu72zkit.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%2Fp5ditogm0uwhlu72zkit.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dropdown ref points to the actual DOM node of the dropdown panel:&lt;br&gt;
{activeDropdown &amp;amp;&amp;amp; (&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;

&lt;p&gt;)}&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%2F7i31regscbkben7il2qy.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%2F7i31regscbkben7il2qy.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any click inside this element should not close the dropdown.&lt;/p&gt;

&lt;p&gt;To determine where a click occurred:&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%2Fa3dpkodff83k4c9xhbfs.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%2Fa3dpkodff83k4c9xhbfs.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the document listener, check:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Was the click on a filter button?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const clickedFilterButton = event.target.closest("[data-filter]");&lt;/code&gt;&lt;br&gt;
This finds the nearest ancestor with the data-filter attribute.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Was the click inside the dropdown panel?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use contains() to check whether the clicked element is inside the dropdown.&lt;/p&gt;

&lt;p&gt;If true, do nothing. The dropdown should stay open.&lt;/p&gt;

&lt;p&gt;Why My Previous parentElement Logic Failed&lt;br&gt;
The previous approach relied on event.target.parentElement.id to match the active dropdown’s ID.&lt;/p&gt;

&lt;p&gt;However, event.target is unpredictable:&lt;/p&gt;

&lt;p&gt;If the user clicks the  icon inside a button, event.target becomes the  element, not the .&lt;/p&gt;

&lt;p&gt;event.target.parentElement.id may then point to a  with no ID, rather than the intended button.&lt;/p&gt;

&lt;p&gt;This approach is Harder to scale. Every nested element requires careful handling.&lt;/p&gt;

&lt;p&gt;It is DOM-dependent, therfore, changes to the DOM structure break the logic.&lt;/p&gt;

&lt;p&gt;This makes assumptions about parent-child relationships.&lt;/p&gt;

&lt;p&gt;Dropdown Toggle Logic&lt;br&gt;
activeDropdown stores the ID of the currently active dropdown (or null if none).&lt;/p&gt;

&lt;p&gt;Clicking the same dropdown again closes it. Clicking a different one switches to the new dropdown.&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%2Fsflu6pjuwghyf6znbc3i.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%2Fsflu6pjuwghyf6znbc3i.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&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%2F9tt1jwkeufv28wj05r5d.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%2F9tt1jwkeufv28wj05r5d.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dropdown closes only if the click is outside.&lt;/p&gt;

&lt;p&gt;Clicking a different dropdown switches the active state.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>react</category>
    </item>
    <item>
      <title>The .sort() in React improved my understanding of State, Mutation, and Data Flow</title>
      <dc:creator>The Naija Debugger </dc:creator>
      <pubDate>Sat, 03 Jan 2026 13:14:08 +0000</pubDate>
      <link>https://dev.to/naijadebugger/the-sort-in-react-improved-my-understanding-of-state-mutation-and-data-flow-4b8b</link>
      <guid>https://dev.to/naijadebugger/the-sort-in-react-improved-my-understanding-of-state-mutation-and-data-flow-4b8b</guid>
      <description>&lt;p&gt;I’ve just finished implementing the sort feature for my e-commerce website.&lt;/p&gt;

&lt;p&gt;Initially, my sorting logic was scattered everywhere - Inside availability filters and within sort conditions themselves. While it worked, it was messy and hard to maintain. I realized that filtering decides what shows, while sorting decides the order. Sorting should happen once, only after all filters are applied. This separation made the logic easier to reason about and scale.&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%2F79blbzzjytloqmqjs94m.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%2F79blbzzjytloqmqjs94m.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;filteredProducts = filteredProducts.sort(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sometimes it worked. Other times it didn’t.&lt;br&gt;
That inconsistency was the red flag.&lt;/p&gt;

&lt;p&gt;sort() mutates the array it’s called on.&lt;br&gt;
In React, mutating an existing array - especially derived state like filteredProducts - can cause unpredictable UI behavior because React cannot detect the change. That’s why sorting would often fail.&lt;/p&gt;

&lt;p&gt;It worked after I switched to the spread operator:&lt;br&gt;
&lt;code&gt;[...filteredProducts].sort(...)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;[...filteredProducts] creates a new array reference, so .sort() only mutates the copy. React detects the new reference and re-renders correctly.&lt;/p&gt;

&lt;p&gt;It is important to remmember:&lt;/p&gt;

&lt;p&gt;[...array] is used when reordering data.&lt;/p&gt;

&lt;p&gt;{ ...item } is used when updating object properties.&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%2Fpx3m51sq6ozt4wrx96p8.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%2Fpx3m51sq6ozt4wrx96p8.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&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%2Fm90pyiebu0jkgeugaaem.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%2Fm90pyiebu0jkgeugaaem.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;String Sorting&lt;br&gt;
For alphabetical sorting, use localeCompare() - it handles uppercase vs. lowercase properly and produces a predictable order.&lt;/p&gt;

&lt;p&gt;A to Z:&lt;br&gt;
&lt;code&gt;a.name.localeCompare(b.name)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Z to A:&lt;br&gt;
&lt;code&gt;b.name.localeCompare(a.name)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Price Sorting&lt;br&gt;
Low to high:&lt;/p&gt;

&lt;p&gt;a.price - b.price&lt;/p&gt;

&lt;p&gt;b.price - a.price&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%2F0vpoxol7qeb2xsowj9bj.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%2F0vpoxol7qeb2xsowj9bj.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&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%2Fvi7ne9xtus5tv7f3k03b.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%2Fvi7ne9xtus5tv7f3k03b.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sorting by Date in Real E-commerce Apps&lt;br&gt;
My initial data didn’t include dates, so I added them properly.&lt;br&gt;
Dates are typically stored in ISO format:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"2024-11-02T14:30:00Z"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This format is backend-friendly, database-friendly, and JavaScript-friendly.&lt;/p&gt;

&lt;p&gt;Most real apps use createdAt (when the product was added) or sometimes updatedAt.&lt;/p&gt;

&lt;p&gt;Old to new:&lt;br&gt;
&lt;code&gt;new Date(a.createdAt) - new Date(b.createdAt)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;New to old:&lt;br&gt;
&lt;code&gt;new Date(b.createdAt) - new Date(a.createdAt)&lt;br&gt;
&lt;/code&gt;&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%2F39ausjalqmj08z1b9kaw.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%2F39ausjalqmj08z1b9kaw.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&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%2Fvi5diw30rgafl903xjyj.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%2Fvi5diw30rgafl903xjyj.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By separating filtering and sorting, avoiding direct mutation, and using consistent comparison methods, my sorting feature now works reliably — and my React state updates predictably.&lt;/p&gt;

&lt;p&gt;github repo: &lt;a href="https://github.com/victorugs-dev/shopco" rel="noopener noreferrer"&gt;https://github.com/victorugs-dev/shopco&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;live demo: &lt;a href="https://shopco-store-sigma.vercel.app" rel="noopener noreferrer"&gt;https://shopco-store-sigma.vercel.app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>onSubmit in React.js Forms: Why action="" and method="" don’t apply anymore</title>
      <dc:creator>The Naija Debugger </dc:creator>
      <pubDate>Mon, 17 Nov 2025 17:50:05 +0000</pubDate>
      <link>https://dev.to/naijadebugger/onsubmit-in-reactjs-forms-why-action-and-method-dont-apply-anymore-3dg7</link>
      <guid>https://dev.to/naijadebugger/onsubmit-in-reactjs-forms-why-action-and-method-dont-apply-anymore-3dg7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Back then in HTML, we would use:&lt;/strong&gt;&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%2Fmgpm4tok15ubz3wmvo8z.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%2Fmgpm4tok15ubz3wmvo8z.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&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%2Fzams776sk3vt5h4zgemn.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%2Fzams776sk3vt5h4zgemn.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The browser handles everything automatically.&lt;/p&gt;

&lt;p&gt;But in React, we don’t let the browser reload the page - we handle it manually.&lt;/p&gt;

&lt;p&gt;Using onSubmit in React lets you control what happens when the form is submitted:&lt;/p&gt;

&lt;p&gt;function MyForm() {&lt;br&gt;
  const handleSubmit = (e) ={&lt;br&gt;
 // &lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;return (&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Submit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Why this approach?&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
No page reloads&lt;/p&gt;

&lt;p&gt;You control the logic&lt;/p&gt;

&lt;p&gt;Perfect for validations&lt;/p&gt;

&lt;p&gt;Works well with APIs (fetch/axios)&lt;/p&gt;

&lt;p&gt;Better user experience&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Capturing inputs with useState&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
React uses controlled components:&lt;/p&gt;

&lt;p&gt;const [name, setName] = useState("");&lt;/p&gt;

&lt;p&gt;
  value={name}&lt;br&gt;
  onChange={(e) =&amp;gt; setName(e.target.value)}&lt;br&gt;
/&amp;gt;&lt;/p&gt;

&lt;p&gt;This gives you full control of the data.&lt;/p&gt;

&lt;p&gt;React forms felt strange at first, but once you understand onSubmit, preventDefault(), and useState, everything starts to click.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>coding</category>
    </item>
    <item>
      <title>Building My First To-Do List App with JavaScript</title>
      <dc:creator>The Naija Debugger </dc:creator>
      <pubDate>Sat, 22 Feb 2025 20:22:35 +0000</pubDate>
      <link>https://dev.to/naijadebugger/building-my-first-to-do-list-app-with-javascript-3a1a</link>
      <guid>https://dev.to/naijadebugger/building-my-first-to-do-list-app-with-javascript-3a1a</guid>
      <description>&lt;p&gt;Building My First To-Do List App with JavaScript&lt;/p&gt;

&lt;p&gt;I built a simple To-Do List App where you can add tasks, mark them as done, and delete them. But there was a catch—everything disappeared on refresh! 😅&lt;/p&gt;

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

&lt;p&gt;✅ Add a task through a form&lt;br&gt;
✅ Mark tasks as completed with a checkbox&lt;br&gt;
✅ Delete tasks with a button&lt;/p&gt;

&lt;p&gt;I used HTML, CSS, and JavaScript to bring it to life.&lt;/p&gt;

&lt;p&gt;Biggest Challenges &amp;amp; Fixes&lt;/p&gt;

&lt;p&gt;❌ Form refreshing on submit → Solved with event.preventDefault()&lt;br&gt;
❌ Incorrect checkbox handling → Switched from click to change event&lt;br&gt;
❌ Struggled with setAttribute('onclick') → Used addEventListener instead&lt;/p&gt;

&lt;p&gt;Each bug taught me something new! 🚀&lt;/p&gt;

&lt;p&gt;What’s Next?&lt;/p&gt;

&lt;p&gt;I plan to store tasks in localStorage so they don’t disappear on refresh.&lt;/p&gt;

&lt;p&gt;I plan to improve it's responsiveness so it can accommodate more tasks.&lt;/p&gt;

&lt;p&gt;Check out the User-Interface and code and let me know what you think! What would you improve?💭&lt;/p&gt;

&lt;p&gt;💻 Deployed the app on Vercel! Try it out here 👉 &lt;a href="https://to-do-list-coral-three-64.vercel.app/" rel="noopener noreferrer"&gt;https://to-do-list-coral-three-64.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📂 Code is open-source—check out the repo on GitHub: &lt;a href="https://github.com/cvictorugs/mini-projects/tree/main/to-do-list" rel="noopener noreferrer"&gt;https://github.com/cvictorugs/mini-projects/tree/main/to-do-list&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📝 Wrote a full breakdown of the process on Medium: &lt;a href="https://medium.com/@cvictorugs/building-my-first-to-do-list-app-with-html-css-and-javascript-b008dd8f84ec" rel="noopener noreferrer"&gt;https://medium.com/@cvictorugs/building-my-first-to-do-list-app-with-html-css-and-javascript-b008dd8f84ec&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What would you improve in this app? I’d love to see it! 🚀 Drop your link in the comments or tag me on Twitter: &lt;a href="https://twitter.com/cvictorugsDEV" rel="noopener noreferrer"&gt;https://twitter.com/cvictorugsDEV&lt;/a&gt; LinkedIn : &lt;a href="https://www.linkedin.com/in/chibuikem-victor-ugwu-b9710a344?trk=contact-info" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/chibuikem-victor-ugwu-b9710a344?trk=contact-info&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>100daysofcode</category>
    </item>
  </channel>
</rss>
