Variants – a quick tip for better React components

A pattern I've seen lots is adding a bunch of booleans to cover different use-cases of a reusable #React component. This makes components hard to use

A variant prop has worked great so far 🧵

swizec.com/blog/variants-…
You start with a smol reusable component

Then it grows, you boolean all the things ImageImage
And your component blows up in complexity. At 3 bools you have 8 different ways to hold your component.

You think you'll get it right every time? Debugging becomes into a game of whack-a-mole Image
Are all 8 combinations valid? Probably not.

Identify the valid combos and turn them into variants. With TypeScript your team even gets autocomplete for available variants 😍 ImageImage
This is a lesson that feels obvious and you learn it many times per year. I remember @kyleshevlin talking about this and thinking "D'oh obvious"

6 months later and I had a codebase full of boolean'd components. It sneaks up on you! Image
This is a pattern that feels obvious but you learn it a few times per year. I remember @kyleshevlin talking about it on Twitter and thinking "D'oh that's obvious"

6 months later I had a codebase full of hard to use boolean'd components 😂 Image

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Swizec Teller

Swizec Teller Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Swizec

19 Jan
Got so close to working Firebase support in useAuth last night I can almost smell it 🤞

here's a recap 🧵

swizec.com/blog/codewiths…
We finished the stream with a broken flow. A callback doesn't callback, very strange.

And we found that Firebase is "hot garbage" as @tannerlinsley called it. Confusing API, strange docs, odd types.

Worst part of working with Firebase is Google's SEO.

Paste error into Google, get the docs. Docs don't even mention the error. 🙊
Read 5 tweets
23 Jun 20
Been having an interesting debate about "managing up" with some friends this morning and interesting patterns cropped up

👇
1) Managing up with a bad manager feels like you're doing their job. You aren't, but it feels like you are.

This is when folks are most frustrated and complain. It sucks for everyone involved.

Manager thinks you're unmanageable. You think manager just gets in the way.
2) Managing up with a great manager feels like Just Communication.

They set direction and talk company priorities.
You decide how to achieve those priorities, communicate blockers and hiccups, proactively say what's up, and keep the manager informed.
Read 6 tweets
17 Feb 19
Some fun stats from product sidehustle land 👇

Since March 2015

2695 hours
1.8 hrs/day average

3-ish products
~2800 sales
$139,208 revenue post fees
$81,767 expenses

$21/hour 🤔

This must be why most people share only the revenue numbers #open
Now the obvious question: Why would anyone do this?

Well for starters it's still better than a coding job back home. My first job building websites was for $7/hour.

That was in high school.
I eventually got better jobs, yes. Mostly thanks to moving into freelancing, being picky about clients, and choosing to work for foreign clients (primarily US startup land) whenever possible.

That got me to about $70,000/year. It was great. Lived like a king.
Read 14 tweets
5 Apr 18
LEARN WHILE YOU POOP: Why you should learn React 🧐

Hi 👋 I’m trying something new and need your feedback. What do you think of this as a format for a daily 2min video?

No pressure learning at 2 minutes per day.Start with WHY React all the way to a React 16.3 master in a month.
LEARN WHILE YOU POOP: Why are components so great 🤔

React, Vue, Angular, or whatever. Components are the future and you should learn how to think in them. Here's why 👇

Hint: it's a lot like LEGO except you also have a 3D printer to make your own.
LEARN WHILE YOU POOP 3
How JSX makes your life easier 👇

Some still debate it, but I love how JSX lets you get in there and get your hands dirty right with the stuff your code is meant to be outputting. Like a top chef 👩‍🍳 gently massaging a steak. 🥩
Read 31 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!