MHD
banner
mhd.codes
MHD
@mhd.codes
certified typescript lover boy 🧙‍♂️ | maintainer @codiume
Look me in the eyes and tell me this code isn't beautiful.
January 9, 2025 at 10:16 PM
Arrays are like standard JavaScript arrays. a bag of elements that can grow or shrink.

Tuples, on the other hand, are fixed in length and type. They know exactly how many elements they contain and the specific types of elements at each position.
January 3, 2025 at 12:49 PM
In #TypeScript, Arrays and Tuples are not the same, So how do we differentiate between the two at the type level? The following type does exactly that using a clever trick (explained in the replies):
January 3, 2025 at 12:49 PM
By the way, here’s the usual way to get the last element of a tuple:
December 30, 2024 at 5:46 PM
I stumbled upon this piece of #TypeScript art, a type helper that cleverly gets the last element of any tuple type. (explanation in the replies)
December 30, 2024 at 5:46 PM
December 18, 2024 at 9:44 AM
I've completed Day 15 - Advent of Typescript 2024 adventofts.com/events/2024/15
December 16, 2024 at 9:13 AM
Advent of Typescript: Day 14
December 14, 2024 at 9:13 PM
The astro schema package is reaching a nice milestone, so I thought I’d share it with you, go
@astro.build 🚀
December 9, 2024 at 10:53 AM
React 18 is a thing of the past, hail the new king, React 19!
December 6, 2024 at 6:13 AM
features i’m excited about in react 19
December 5, 2024 at 10:13 PM
in case you wondering how you navigate between links:
November 10, 2024 at 12:43 PM
Say hello to my new react router
November 10, 2024 at 12:43 PM
the early return pattern in all its glory #javascript
November 6, 2024 at 1:12 PM
oss tip: never publish unscoped npm packages. always use an organization scope, as npm accounts don’t allow username changes. to change a username, you’ll need to create a new account and transfer all packages to it. orgs, however, can have multiple owners, and it's easy to add or remove members.
November 2, 2024 at 10:27 AM
November 1, 2024 at 11:16 AM
if you've been using tanstack router lately, you know it has this killer feature: "type-safe routes". and believe me once you experience the ergonomics of using a type-safe router, you'll never want to go back to be a cave men again. so what if #Nextjs had that ?
October 31, 2024 at 3:17 PM
You might ask why bother, so here's a snippet of what the above code would look like if it were written without this reusable hook
August 3, 2024 at 11:59 AM
Today's React hook is a syntax sugar on top of the native browser API for adding events.
It aligns better with React's declarative nature, and keeps your code clean, consistent, while abstracting away the logic for adding/removing events✨. #CodeOfTheDay #ReactJS
August 3, 2024 at 11:59 AM
#CodeOfTheDay: Smart polling with TanStack Query!

Need to monitor long-running backend tasks without WebSocket overhead? This hook auto-polls your API every 5 seconds, stopping when the job's done.

Simple, efficient, perfect for tracking task progress.
August 2, 2024 at 11:12 AM
July 31, 2024 at 11:23 AM
🖱️ #CodeOfTheDay: The 'useClickOutside' hook!

One of the most commonly used hooks, for detecting clicks outside of a specific element. Perfect for closing modals, dropdowns, or any clickaway interaction.

Usage Example in🧵
July 31, 2024 at 11:23 AM
🔢 Today's #CodeOfTheDay: A React `useCounter` hook with a built-in clamp functionality!
This custom hook manages a counter state with increment, decrement, and reset actions, all while keeping the value within specified bounds.
July 30, 2024 at 6:53 PM
Today's #CodeOfTheDay: The 'clamp' function

It ensures a number stays within a specified range. If it's too low, it becomes the minimum. Too high? It's capped at the maximum.
July 29, 2024 at 4:44 PM
July 27, 2024 at 5:10 PM