<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp" -->

---
title: How to write a React Component in TypeScript | daily.dev
description: A common method to typing a React component is to use one of the generics that are built-into @types/react (I mean, it's built-in right? So what could go...
canonical: https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to write a React Component in TypeScript | daily.dev
og:description: A common method to typing a React component is to use one of the generics that are built-into @types/react (I mean, it's built-in right? So what could go...
og:url: https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp
og:image: https://api.daily.dev/og/posts/xwQT2fqJP.png
og:image:alt: How to write a React Component in TypeScript
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to write a React Component in TypeScript

**[Kent C. Dodds](https://daily.dev/sources/kentcdodds)** · [@kentcdodds](https://daily.dev/kentcdodds) · 6 min read · 18 upvotes · 1 comments

## Summary

A common method to typing a React component is to use one of the generics that are built-into @types/react (I mean, it's built-in right? So what could go wrong?). Interestingly, you cannot type a function declaration this way, so we'll have to use a function expression. For functions, you need to consider the types coming in and the types going out.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://kentcdodds.com/blog/how-to-write-a-react-component-in-type-script>

## Community discussion

Top comments from developers on daily.dev.

**@vmo\_campos** · 1 upvotes

> Genial. Kent creation some pure functions, using the best of lang can provide.

---

Tags: [#react](https://daily.dev/tags/react), [#typescript](https://daily.dev/tags/typescript)

[View this post on daily.dev](https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to write a React Component in TypeScript","url":"https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp"},"datePublished":"2021-03-04T23:18:16.475Z","dateModified":"2021-10-07T14:17:10.317Z","description":"A common method to typing a React component is to use one of the generics that are built-into @types/react (I mean, it's built-in right? So what could go...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2b06efbf67c3bd73da049dc109d0ed98","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2b06efbf67c3bd73da049dc109d0ed98","isAccessibleForFree":true,"articleSection":"Kent C. Dodds","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Person","name":"Kent C. Dodds","url":"https://daily.dev/kentcdodds","image":"https://avatars.githubusercontent.com/u/1500684?v=4","description":"My name is Kent C. Dodds and I'm a JavaScript engineer and teacher. I'm also active in the open source community. I like my family, JavaScript, and React.","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":1780}},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":18},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"react,typescript","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kent C. Dodds","item":"https://daily.dev/sources/kentcdodds"},{"@type":"ListItem","position":3,"name":"How to write a React Component in TypeScript"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-write-a-react-component-in-typescript-xwqt2fqjp","comment":[{"@type":"Comment","text":"Genial. Kent creation some pure functions, using the best of lang can provide.","datePublished":"2021-03-05T03:06:41.327Z","url":"https://daily.dev/posts/xwQT2fqJP#c-7IxRCvTmH","author":{"@type":"Person","name":"Vinicius Mateus","url":"https://daily.dev/vmo_campos","image":"https://lh3.googleusercontent.com/a-/AOh14GjubYGrgZKF6qTUDlBU2j0AtSQtJTf7a4xEUWPO1Q=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}]}
```

