nico.fyi
Published on

Advent of Pull Requests Best Practice - Day 16

Authors
  • avatar
    Name
    Nico Prananta
    Twitter
    @2co_p
Advent of Pull Requests Best Practice - Day 16

Let's talk about something that's often overlooked but super important in web development: Data Validation. You know, that thing we should be doing every time our app talks to an external source, like a database or a third-party service.

I've noticed a trend where devs pull data from these sources and just slam it into the app. No checks, no balances. Just raw, unfiltered data going straight into the system. Here's a classic oopsie we've all probably done:

const data = await fetch(`https://some-third-party-api`)
setName(data['result']['user']['name'])

Looks harmless, right? But oh boy, can it wreak havoc! What if user is undefined? Or name decided to take a day off? Boom! Your app goes kaput.

And here's the kicker: when someone else jumps into your code, they're going to have a million questions. What's in user? Is it always there? It's like a mental workout nobody signed up for.

So, here's a pro tip: Always validate external data. In JavaScript/TypeScript world, you can use zod or yup, for example. Make it your mantra, especially when you're reviewing a pull request. Trust me, your future self (and your team) will thank you for saving them from the potential headaches of data disasters.

Stay sharp and validate!

📖 Early Bird Offer

Need more insights like this? Jump on our early bird offer and grab your copy for 40% less! This deal is flying off the shelves, so hurry! 🎉