---
title: "Discussion on \"A neat way of building React components\" | Hashnode"
description: "Discussion on \"A neat way of building React components\". I'll explain one of the best way (in my opinion) to keep your React components\nclean and reusable. I'll be using TypeScript for this and we'll start with\na simple Button component:\ntype Props = {\n  children: string\n}\n\nfunction Button({ children }: Pr..."
url: "https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [A neat way of building React components](https://h.telmo.is/a-neat-way-of-building-react-components?utm_source=hashnode&utm_medium=feed)

I'll explain one of the best way (in my opinion) to keep your React components clean and reusable. I'll be using TypeScript for this and we'll start with a simple Button component: type Props = { children: string } function Button({ children }: Pr...

Feb 9, 2021 · 4 min read · h.telmo.is  
Read the article

-   [#tutorial](https://hashnode.com/tag/tutorial)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#reactjs](https://hashnode.com/tag/reactjs)

## Written by

[Telmo Goncalves](https://hashnode.com/@telmo)

@telmo · Portugal

  
[View profile](https://hashnode.com/@telmo)

Developer who can design.

I've been a developer and designer for well over a decade. I write about JavaScript, React, Tailwind, Next.js and much more.

## Responses 5

Markdown supported · ⌘↵ to post

[Saša Šijak](https://hashnode.com/@ssijak)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/6024e3a14d9e7d4dd727e022)

For me it is much cleaner to do it like this:

```
size: "sm" | "md" | "lg"
```

That way you do not have to import `Sizes` type everywhere and type it in each prop and you still get type check

[Telmo Goncalves](https://hashnode.com/@telmo)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/6024e3a14d9e7d4dd727e022#reply-6024ec6e8a18494dfcecc047)

The only reason I would disagree with this is, lets picture you're using `<Button size="md">` is hundreds of places in your app. Now, you get a requirement to change it from `md` to `medium`.

With the `enum` you only need to change it in the `Button` component itself, you don't need to go over every single scenario where you're using it and change to `medium`.

[Surjith S M](https://hashnode.com/@surjithctly)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/6024de728a18494dfcecbf4e)

I didn’t understand.

Apart from using Typescript? What’s the benefit? Are you suggesting to use typescript for better components or to use `enum`? If its not typescript, how do we go about it.

Am I missing something?

[Telmo Goncalves](https://hashnode.com/@telmo)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/6024de728a18494dfcecbf4e#reply-6024ece68a18494dfcecc04c)

I'm using `enum` because of TypeScript though. If you're not using TS you can do:

```
export const sizes = {
  MD: 'md',
  // etc
}
```

The benefit is that you'll have the size names or button types all in the same place. If you need to change from `lg` to `large` you only need to change it in one place.

[Surjith S M](https://hashnode.com/@surjithctly)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/6024de728a18494dfcecbf4e#reply-602501a44d9e7d4dd727e29d)

[Telmo Goncalves](https://hashnode.com/@telmo) Oh Okay. Got it now. Thanks for clarifying.

[Catalin Pit](https://hashnode.com/@Catalinpit)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/6024ce3950d5e944c5d48054)

Ooo, you joined the TypeScript "cult"! 😂

Haha, jokes aside, great article! 👏

[Prasanna Kumar](https://hashnode.com/@prasannarkumar)

[Feb 11, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/60248f8480da6c44eadf7b8d)

I too think this is a good way to maintain components. Thanks for sharing Telmo.

[Shamel Lakin](https://hashnode.com/@Shamel)

[Feb 10, 2021](https://hashnode.com/posts/a-neat-way-of-building-react-components/60229875aaa3543c903bfbc9/comment/60242a9850d5e944c5d47880)

Great work Telmo!
